2017-11-16 12 views
0

얘들 아, 나는 모든 데이터를 row_cats에 저장하고 하나씩 차례로 호출하려고하는데 여기에 갇혀있다.mysqli_multi_query while while loop php

$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']; 
+2

은 SQL이 그런 식으로 작동하지 않습니다 시도 할 수 있습니다 – Forbs

답변

-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)); 
}