mysqli_multi_query在while循环php中不起作用

时间:2017-11-16 04:50:03

标签: php sql mysqli mysqli-multi-query

伙计们,我被困在这里,因为我试图将所有数据存储到row_cats然后逐个调用。

$get_cats = "select * from categories";

$get_cats .= "select * from products order by rand() LIMIT 0,4"

$run_cats =mysqli_multi_query($con,$get_cats);

while($row_cats=mysqli_fetch_array($run_cats)){

     $cat_id = $row_cats['cat_id'];//from first query

     $cat_title = $row_cats['cat_title'];
     $pro_id=$row_products['products_id'];//from second query
     $pro_title=$row_products['product_title'];
     $pro_cat=$row_products['cat_id'];
     $pro_image=$row_products['product_img1'];

1 个答案:

答案 0 :(得分:-1)

你可以尝试

 $get_cats = "select * from categories;";    **// give semicoln inside the double quotes**

 $get_cats .= "select * from products order by rand() LIMIT 0,4"

// Execute multi query
if (mysqli_multi_query($con,$get_cats))
{
 do
 {
  // Store first result set
   if ($result=mysqli_store_result($con)) {
   // Fetch one and one row
   while ($row=mysqli_fetch_row($result))
    {
    printf("%s\n",$row[0]);
    }
   // Free result set
   mysqli_free_result($result);
   }
 }
 while (mysqli_next_result($con));
}
相关问题