php - How to run query until one record is found? -
this trying right no luck
$bid  = $next - 2;//this subtracts 2 number, number auto generated       $preid = $bid;     $query = "select *  images imageid = '$preid'";     $sql = mysqli_query($conn,$query) or die(mysqli_error($conn));      while(mysqli_num_rows($sql) !=0) {         $select_query = "select *  images imageid = '$preid'";         $sql = mysqli_query($conn,$select_query) or die(mysqli_error($conn));         --$preid;     }    whats suppose happen if record not exist subtracts 1 preid , runs query again new preid , keeps happening until record found cant figure out how it.
i assuming checking database new values. however, on large scale application thi highly inefficient way ping database. have made variable $preid not using anywhere.
 how if go according way
$bid  = $next - 2;//this subtracts 2 number, number auto generated   $preid = $bid; $query = "select *  images imageid = '$preid'"; $sql = mysqli_query($conn,$query) or die(mysqli_error($conn));  while(mysqli_num_rows($sql) !=0 || !$preid) { //notice here added condition preid.     $select_query = "select *  images imageid = '$preid'";     $sql = mysqli_query($conn,$select_query) or die(mysqli_error($conn));     --$preid; }    now happens loop run long either of 2 condition stays true ie either row returned database or keep searching until preid not 0.
Comments
Post a Comment