简体   繁体   中英

Can not fetch data randomly using PHP and MySQL

I need one help.I am trying to fetch data randomly using PHP and MySQL but its not happening like that. I am explaining my code below.

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

From the above query i can not get the random data.Please help me to resolve this issue.

仅使用ORDER BY RAND()来获取随机数据:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM