mysql 理解一个PHP语句[重复]

yvfmudvl  于 2023-04-29  发布在  Mysql
关注(0)|答案(1)|浏览(109)

此问题已在此处有答案

Reference Guide: What does this symbol mean in PHP? (PHP Syntax)(25个回答)
8天前关闭
我试图让我的头周围这下面的代码,相对较新的php/mysql它有点挠头,我试图解决的部分是进度/百分比的一部分。

$prog = $tprog > 0 ? ($cprog/$tprog) * 100 : 0;

$prog = $prog > 0 ?  number_format($prog,2) : $prog;

如果有人能解释就好了

<?php
            $i = 1;
            $stat = array("Started (Received by Client)","In-Progress (with Estimator)","Complete (Handed to Delivery)");
            $where = "";
            if($_SESSION['login_type'] == 2){
              $where = " where manager_id = '{$_SESSION['login_id']}' ";
            }elseif($_SESSION['login_type'] == 3){
              $where = " where concat('[',REPLACE(user_ids,',','],['),']') LIKE '%[{$_SESSION['login_id']}]%' ";
            }
            $qry = $conn->query("SELECT * FROM project_list $where order by name asc");
            while($row= $qry->fetch_assoc()):
              $prog= 0;
            
            $tprog = $conn->query("SELECT * FROM task_list where project_id = {$row['id']}")->num_rows;
            $cprog = $conn->query("SELECT * FROM task_list where project_id = {$row['id']} and status = 3")->num_rows;
            $prog = $tprog > 0 ? ($cprog/$tprog) * 100 : 0;
            $prog = $prog > 0 ?  number_format($prog,2) : $prog;
            $prod = $conn->query("SELECT * FROM user_productivity where project_id = {$row['id']}")->num_rows;
            if($row['status'] == 0 && strtotime(date('Y-m-d')) >= strtotime($row['start_date'])):
            if($prod  > 0  || $cprog > 0)
              $row['status'] = 2;
            else
              $row['status'] = 1;
            elseif($row['status'] == 0 && strtotime(date('Y-m-d')) > strtotime($row['end_date'])):
            $row['status'] = 4;
            endif;
              ?>
w46czmvw

w46czmvw1#

1.设置项目状态数组$stat,其中包含三个元素:"Started (Received by Client)""In-Progress (with Estimator)""Complete (Handed to Delivery)"
1.根据用户的登录类型设置变量$where(manager --查询将按其ID过滤-- team member --在project_list表的user_ids字段中按其ID过滤)
1.执行SQL查询,根据$where筛选器从project_list表中选择所有项目
1.循环查询返回的每个项目+计算项目进度%
(计算进度百分比-- 1获取项目的任务总数$tprog+已完成的任务数$cprog--如果项目没有任务--将百分比设置为0,否则计算(已完成的任务/总任务)* 100)
1.使用number_format将百分比格式设置为两位小数
1.根据开始和结束日期检查项目状态+是否已完成任何任务
1.在HTML表格行中输出项目名称+进度百分比+状态

相关问题