在php中显示两个sql查询的结果表
我正在编写一个php文件,我想通过执行两个单独的查询来显示两个表,并将它们存储在$result和$result\u中。但是,当我尝试打开此操作表单的html页面时,它仅显示第一个查询的表,并在第二个表的位置显示错误“命令不同步;您现在无法运行此命令” 另外,我不想合并这两个表,因为它们显示完全不同的信息,我想插入一些文本来解释每个表 我认为这可能与无法为php打印两个表有关(我对此表示怀疑)?我应该做什么改变 提前感谢您的帮助在php中显示两个sql查询的结果表,php,mysql,Php,Mysql,我正在编写一个php文件,我想通过执行两个单独的查询来显示两个表,并将它们存储在$result和$result\u中。但是,当我尝试打开此操作表单的html页面时,它仅显示第一个查询的表,并在第二个表的位置显示错误“命令不同步;您现在无法运行此命令” 另外,我不想合并这两个表,因为它们显示完全不同的信息,我想插入一些文本来解释每个表 我认为这可能与无法为php打印两个表有关(我对此表示怀疑)?我应该做什么改变 提前感谢您的帮助 $result = mysql_query("CAL
$result = mysql_query("CALL CrashTypeRate_Ped('$city')", $conn);
if (!$result){
echo "Fail to retrieve result for pedestrian crashes!\n";
print mysql_error();
} else {
echo "<table border=1>\n";
echo "<tr><td>CrashType</td><td>Count</td><td>TotalCount</td></tr>\n";
while ($myrow = mysql_fetch_array($result)) {
printf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n", $myrow["crash_type"], $myrow["type_count"], $myrow["total_count"]);
}
echo "</table>\n";
}
$result_bike = mysql_query("CALL CrashTypeRate_Bike('$city')", $conn);
if (!$result_bike) {
echo "Fail to retrieve result for bike crashes!\n";
print mysql_error();
} else {
echo "got here!!!!!!";
echo "<table border=1>\n";
echo "<tr><td>CrashType</td><td>Count</td><td>TotalCount</td></tr>\n";
while ($myrow = mysql_fetch_array($result_bike)) {
printf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n", $myrow["crash_type"], $myrow["type_count"], $myrow["total_count"]);
}
echo "</table>\n";
}
$result=mysql\u query(“调用CrashTypeRate(“$city”),$conn);
如果(!$result){
echo“无法检索行人碰撞的结果!\n”;
打印mysql_错误();
}否则{
回音“\n”;
回显“CrashTypeCountTotalCount\n”;
while($myrow=mysql\u fetch\u数组($result)){
printf(“%s%s%s\n”、$myrow[“崩溃类型”]、$myrow[“类型计数”]、$myrow[“总数计数”]);
}
回音“\n”;
}
$result\u bike=mysql\u query(“调用CrashTypeRate\u bike(“$city”),$conn);
如果(!$result\u自行车){
echo“无法检索自行车碰撞的结果!\n”;
打印mysql_错误();
}否则{
echo“到了这里!!!!!!!”;
回音“\n”;
回显“CrashTypeCountTotalCount\n”;
而($myrow=mysql\u fetch\u数组($result\u bike)){
printf(“%s%s%s\n”、$myrow[“崩溃类型”]、$myrow[“类型计数”]、$myrow[“总数计数”]);
}
回音“\n”;
}
以下是PHP文档用户评论。希望这有帮助
调用多个存储过程时,可能会遇到以下错误:“命令不同步;现在无法运行此命令”。
即使在调用之间对结果对象使用close()函数,也可能发生这种情况。
要解决此问题,请记住在每次存储过程调用之后调用mysqli对象上的next_result()函数。见下例:
<?php
// New Connection
$db = new mysqli('localhost','user','pass','database');
// Check for errors
if(mysqli_connect_errno()){
echo mysqli_connect_error();
}
// 1st Query
$result = $db->query("call getUsers()");
if($result){
// Cycle through results
while ($row = $result->fetch_object()){
$user_arr[] = $row;
}
// Free result set
$result->close();
$db->next_result();
}
// 2nd Query
$result = $db->query("call getGroups()");
if($result){
// Cycle through results
while ($row = $result->fetch_object()){
$group_arr[] = $row;
}
// Free result set
$result->close();
$db->next_result();
}
else echo($db->error);
// Close connection
$db->close();
?>
非常感谢您!这确实解决了问题:)