dongzaobei0942 2017-02-07 10:45
浏览 19

如何在条件满足php时使用循环计算表行并执行代码

table

id,name,status
1   a    3
2   b    3
3   c    3

i have multiple rows in my table.

when i click submit button it check all rows if status of all rows is 4 then i put save condition else it runs another code.

i need to count rows of my table suppose their are 2 rows with status==3 then my forloop count rows and if all the 2 rows being status ==4 then create save logic..

Please help me to implement

below is my code..but it is not working for me..

$cond = array('OrderDetail.order_id'=>trim($this->requestData['orderId'])); 
$orderData = $this->OrderDetail->find('all',array('conditions'=>$cond));
$numData = sizeof($orderData);
$count=1;
foreach ($orderData as $value) {
    if($value['OrderDetail']['status'] > 3 && $value['OrderDetail']['status']!=5){
        if($numData == $count) {
            // if condition meets and all the rows of table have status==4 then 
            // save logic here
            // }
        }
        $count= $count+1;
    } 
  • 写回答

1条回答 默认 最新

  • dongzha0813 2017-02-07 17:18
    关注

    You can simply do this:

     $cond = array('OrderDetail.order_id'=>trim($this->requestData['orderId'])); 
     // condition for status not equal to 4
     $conditionForStatus = array(
                           'OrderDetail.status !='=>4,
                           // 'OrderDetail.order_id'=>trim($this->requestData['orderId'])
                           );
    
     $orderData = $this->OrderDetail->find('all',array('conditions'=>$cond));
    
     // find count of record where status is not equal to 4
     $countOfStatus = $this->OrderDetail->find('count',array('conditions'=>$conditionForStatus ));
     if(!empty($orderData) && $countOfStatus == 0) {
        // your save logic here
     }
    

    You just need some records in table but having status 4 only. Am i right ?

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答