2016-05-31 52 views
0

我需要一個幫助。我試圖使用PHP和MySQL隨機獲取數據,但它不會像那樣發生。我在下面解釋我的代碼。無法使用PHP和MySQL隨機獲取數據

$day_id=$_GET['day_id']; 
$sql=mysqli_query($connect,"select * from db_restaurant_basic where premium=1 and status=1 order by member_id,rand()"); 
if(mysqli_num_rows($sql) > 0){ 
    while($row=mysqli_fetch_array($sql)){ 
      $member_id=$row['member_id']; 
      $quad_id=$row['quadrant']; 
      $sqlqry=mysqli_query($connect,"select * from db_restaurant_detail where member_id='".$member_id."' and day_id='".$day_id."' and checked=1"); 
      while($details=mysqli_fetch_array($sqlqry)){ 
         $data[]=array("day_id"=>$details['day_id'],"comment"=>$details['comment'],"restaurant_name"=>$row['rest_name'],"member_id"=>$row['member_id'],"available_image"=>$available_image,"city"=>$row['city'],"proviance"=>$row['proviance'],"postal_code"=>$row['postal'],"country"=>$row['country'],"person"=>$row['person'],"mobile"=>$row['mobile'],"url"=>$row['url'],"premium"=>$row['premium'],"image"=>$row['image'],"business_phone_no"=>$row['business_phone_no']); 
      } 
    } 
} 
$result=array("data"=>$data,"imagepath"=>$imagepath); 
echo json_encode($result,JSON_UNESCAPED_SLASHES); 

從上面的查詢我不能得到隨機data.Please幫我解決這個問題。

+0

只使用'ORDER BY RAND()''刪除member_id'。 – RJParikh

回答

3

只能使用ORDER BY RAND()獲得隨機數據:

$sql=mysqli_query($connect,"select * from db_restaurant_basic where premium=1 and status=1 ORDER BY RAND()");