[英]mysql_fetch_array does not work inside the while loop
I have 10 tables known as(table_1,table_2,table_3 etc), currently i want get the result set of each of those tables inside a loop but currently it is returning an error. 我有10个被称为(table_1,table_2,table_3等)的表,目前我想在循环内获取每个表的结果集,但目前它返回错误。
it works fine like this 像这样很好
$excute = ("CALL Dummy_2('table_1')");
$result = mysql_fetch_assoc(mysql_query($excute));
var_dump($result);
Result 结果
array (size=8)
'ID' => string '1' (length=3)
'name' => string 'Test_E' (length=11)
'accountname' => string 'sri01' (length=3)
'accountID' => string '1' (length=1)
'status' => string '2' (length=1)
'total_mps' => string '202' (length=3)
'min(a.timestamp)' => string '2014-05-16 05:38:01' (length=19)
'max(a.timestamp)' => string '2014-12-31 03:41:31' (length=19)
but when i put it inside a loop to fulfill my requirement it returns 9 errors(equal to the remaining number of tables) along with the first result set 但是当我将其放入循环中以满足我的要求时,它会返回9个错误(等于表的剩余数量)以及第一个结果集
$table_count = mysql_query("SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'milepostdb' AND table_name LIKE 'table_%' ");
while($row = mysql_fetch_array($table_count)){
$table = $row["TABLE_NAME"];
$excute = ("CALL Dummy_2('{$table}')");
$result = mysql_fetch_assoc(mysql_query($excute));
var_dump($result);
}
The error 错误
array (size=8)
'ID' => string '1' (length=3)
'name' => string 'Test_E' (length=11)
'accountname' => string 'sri01' (length=3)
'accountID' => string '1' (length=1)
'status' => string '2' (length=1)
'total_mps' => string '202' (length=3)
'min(a.timestamp)' => string '2014-05-16 05:38:01' (length=19)
'max(a.timestamp)' => string '2014-12-31 03:41:31' (length=19)
( ! ) Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean .......
null
( ! ) Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean .......
null
( ! ) Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean .......
null
etc
The function mysql_fetch_assoc(mysql_query($excute)) returns NULL when the query is not executed successfully. 当查询未成功执行时,函数mysql_fetch_assoc(mysql_query($ excute))返回NULL。
Try replacing $execute as follows. 尝试如下替换$ execute。
$excute = "CALL Dummy_2('".$table."')"; $ excute =“ CALL Dummy_2('”。$ table。“')”;
In your case the table name is searched as {$table} and the variable is not replaced in the query. 在您的情况下,表名将搜索为{$ table},并且该变量不会在查询中替换。 This results is a wrong search and no tables will be found. 该结果是错误的搜索,将找不到表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.