0

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.

1
  • use only order by rand() remove member_id. Commented May 31, 2016 at 10:12

1 Answer 1

2

Use only ORDER BY RAND() to get random data:

$sql=mysqli_query($connect,"select * from db_restaurant_basic where premium=1 and status=1 ORDER BY RAND()");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.