【发布时间】:2013-07-10 11:01:13
【问题描述】:
我在堆栈上寻找过类似的东西,但没有完全一样的东西。
我(我想我)需要在循环中生成一个唯一的 MySQL 查询,因为每次迭代都需要查找不同的表。循环来自一个爆炸的 $_GET 数组。
问题是基于循环迭代创建一个不同命名的 mysql 查询。我已经在 $var 名称不同但不起作用的地方完成了它,我认为是因为它是字符串而不是变量?
任何帮助表示赞赏
$temps = explode(",", $_GET['temps']);
$tempCount = count($temps);
for ($i=0; $i<$tempCount; $i++)
{
/*'normal' database lookup
$check = mysql_query("SELECT * FROM _db_".$temps[$i]."");
$checks = array();
while ($row = mysql_fetch_assoc($check)) {
$checks[] = $row;
}*/
//here's where I'm trying to build a 'dynamic' lookup for each loop iteration
$checkTemp=$check.$temps[$i];
$checkTempArray=$check.$temps[$i].'Array';
$checkTemp = mysql_query("SELECT * FROM _db_".$temps[$i]."");
$checkTempArray = array();
while ($row = mysql_fetch_assoc($checkTemp)) {
$checkTempArray[] = $row;
}
}
【问题讨论】:
-
$check 没有被使用
-
“不同名称”的 MySQL 查询是什么意思?
-
我已经对其进行了修改,因此您可以看到每次迭代的 db 表名称都不同。因此,需要存储的数组必须具有不同的名称以供以后查找(foreach 等)。例如数组 $checkJohn 和 $checkSally
-
$checkTemp = mysql_query("SELECT * FROM db".$temp[$i]."");要么使用 $temps[$i] 要么只使用 $temp,$temp[$i] 没有任何意义
-
谢谢,我已经修改了。但我也需要创建一个动态创建的数组,以供以后查找。这是我的主要问题