There are two different queries.
select * from blockinfo where book='$cod' and user='$user'
select * from blockinfo where user='$user' and book='$cod' and flag!=0"
these two queries are to be executed on pages like these example.com and example.com?cod=value. I have to process first query on all rows followed by second query. I have to process using two while loops.
Can I process two queries using single loop?
if($quant!=NULL&&$cod!=NULL&&$user!=NULL&&$quantdb!=NULL&&$title!=NULL){
$sql="select * from blockinfo where book='$cod' and user='$user' ";
$res=mysqli_query($con,$sql);
$numrows=mysqli_num_rows($res);
if($numrows>0){
while($row=mysqli_fetch_assoc($res)){
$flag=$row['flag'];
date_default_timezone_set('Asia/Kolkata');
$current_time=date('Y/m/d H:i:s');
//echo "$current_time ";
$current_time=strtotime($current_time);
$timestamp=strtotime($time)+1*1*60;
$collect_time=date('Y/m/d H:i:s',$timestamp);
//echo "$collect_time ";
$collect_time=strtotime($collect_time);
$difference=$collect_time-$current_time;
$days=floor($difference/86400);
$difference=($difference%86400);
$hrs=floor($difference/3600);
$difference=($difference%3600);
$mins=floor($difference/60);
$difference=($difference%60);
$seconds=floor($difference);
if($days<=0&&$hrs<=0&&$mins<=0&&$seconds<=0){
if($flag==0)
echo "you did not collect the book in time <br/>";
if($flag==1){
$upd="update books set quantity=quantity+'$quant' where code='$cod' ";
mysqli_query($con,$upd);
$flag=0;
$upd2="update blockinfo set flag=0 where book='$cod' and user='$user' and blockedtime='$time'";
mysqli_query($con,$upd2);
}
if($flag==2){
$del="delete from blockinfo where book='$cod' and user='$user' and blockedtime='$time'";
mysqli_query($con,$del);
}
}
else if($flag==1){
echo "you have blocked $quant books of name $title <br/>";
echo "you have $days days $hrs hours $mins minutes $seconds seconds left to collect your book<br/>";
}
}
}
//do something
if($cod==NULL)
$sql="select * from blockinfo ";
$res=mysqli_query($con,$sql);
$numrows=mysqli_num_rows($res);
if($numrows>0){
while($row1=mysqli_fetch_assoc($res)){
$resbook=$row1['book'];
$blockedtime=$row1['blockedtime'];
$user=$row1['user'];
$quant=$row1['quant'];
$flag=$row1['flag'];
date_default_timezone_set('Asia/Kolkata');
$current_time=date('Y/m/d H:i:s');
//echo "$current_time ";
$current_time=strtotime($current_time);
$timestamp=strtotime($blockedtime)+1*1*60;
$collect_time=date('Y/m/d H:i:s',$timestamp);
//echo "$collect_time ";
$collect_time=strtotime($collect_time);
//echo "$flag";
$difference=$collect_time-$current_time;
$days=floor($difference/86400);
$difference=($difference%86400);
$hrs=floor($difference/3600);
$difference=($difference%3600);
$mins=floor($difference/60);
$difference=($difference%60);
$seconds=floor($difference);
if($days<=0&&$hrs<=0&&$mins<=0&&$seconds<=0){
if($flag==1){
$upd="update books set quantity=quantity+'$quant' where code='$resbook' ";
mysqli_query($con,$upd);
$flag=0;
$upd2="update blockinfo set flag=0 where book='$resbook' and user='$user' and blockedtime='$blockedtime'";
mysqli_query($con,$upd2);
}
if($flag==2){
$del="delete from blockinfo where book='$resbook' and user='$user' and blockedtime='$blockedtime'";
mysqli_query($con,$del);
}
}
}
}