douzhe9927 2016-04-09 17:48
浏览 14

使用两个不同的查询处理所有行

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);
                }
              }
          }
      }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?