我的数据库中有大约 20 个表,我在一个 while 循环中运行查询以获取所有表数据并将每个表的数据存储在一个数组中,循环并且一切正常但存储部分不会发生。任何人都可以帮助我将每个表的数据存储在一个数组中
代码
while($row = mysql_fetch_array($table_count)){
$table = $row["TABLE_NAME"];
$excute = mysql_query("
SELECT DISTINCT b.ID, name, accountname, c.accountID, status, total_impr, min(a.timestamp), max(a.timestamp)
FROM $table a INNER JOIN bookers b on a.ID = b.ID INNER JOIN accounts c on b.accountID = c.accountID
WHERE a.timestamp > DATE_ADD(NOW(), INTERVAL -1 YEAR)
GROUP BY ID;") or die(mysql_error());
$result = mysql_fetch_assoc($excute);
$tables = array();
$tables .= $result;
}
print_r($tables);
最佳答案
foreach use this 的语法没有什么错误
foreach ($table as $tables) {
forech 的正确语法是
foreach(array_expression as $variable)
{
}
更新====
$tables = array();
$i=0;
while($row = mysql_fetch_array($table_count))
{
$table = $row["TABLE_NAME"];
$excute = mysql_query("
SELECT DISTINCT b.ID, name, accountname, c.accountID, status, total_impr, min(a.timestamp), max(a.timestamp)
FROM $table a INNER JOIN bookers b on a.ID = b.ID INNER JOIN accounts c on b.accountID = c.accountID
WHERE a.timestamp > DATE_ADD(NOW(), INTERVAL -1 YEAR)
GROUP BY ID;") or die(mysql_error());
while($finalRes = mysql_fetch_assoc($excute))
{
$tables[$i][] = $finalRes;
}
$i++;
}
echo '<pre>';
print_r($tables);
你用错了。
关于php - 为什么不能将我的数据放入关联数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28018981/