亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

多個條目 - PHP 中的計數值

多個條目 - PHP 中的計數值

PHP
慕田峪7331174 2022-05-27 16:38:31
謝謝朋友們的幫助和反饋。我知道我不擅長 PHP,但仍在嘗試學習和使用它:D——我的表包含針對 evaid 作為 Open Close 或 In Process 的重復條目——使用下面的代碼,我從 DB 中獲得了每個條目的最后輸入狀態通過使用查詢和 if 語句來顯示數據的狀態,但我也想獲取它的計數。任何人都可以幫助我---例如---$sql = "SELECT * FROM (SELECT * FROM disagreements ORDER BY addeddate DESC) disagreements  GROUP BY evaid";$result = mysqli_query($conn, $sql);if (mysqli_num_rows($result) > 0) {     while($row = mysqli_fetch_assoc($result))  {   // Here with this query I got last entered status of each row against evaid – as 2 Open – 5 in Process and 10 Closed --- with below if statement – I can echo the rows with status but I want to have count of it that how many are open, in process or closed        if($row["status"]=='Open') {  // I want to count this value as 2                    echo "<tr>";            echo "<td>" . $row["evaid"]. "</td>";            echo "<td>" . $row["status"]. "</td>";            echo "</tr>";        }     }} else {    echo "Nothing to Display";}mysqli_close($conn);
查看完整描述

2 回答

?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

// Hii.. 你可以從你的 SQL 查詢中得到一個計數,試試這個


$sql = "SELECT *, COUNT(ID) AS COUNT FROM (SELECT * FROM disagreements ORDER BY addeddate DESC) disagreements  GROUP BY evaid";

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) 

    while($row = mysqli_fetch_assoc($result)) 

    {   

        if($row["status"]=='Open')   

        {

           echo "<tr>";

           echo "<td>" . $row['count'] . "</td>"; // here you will get a count

           echo "<td>" . $row["evaid"]. "</td>";

           echo "<td>" . $row["status"]. "</td>";

           echo "</tr>";

        }

      } 

    } 

 else 

{

    echo "Nothing to Display";

}

mysqli_close($conn);


查看完整回答
反對 回復 2022-05-27
?
阿晨1998

TA貢獻2037條經驗 獲得超6個贊

<?php 


$count['open']    = 0;


$count['close']   = 0;


$count['process'] = 0;


while($row = mysqli_fetch_assoc($result))  {   


    if($row["status"]=='Open') 

    {         

        $count['open']++;

        echo "<tr>";

        echo "<td>" . $row["evaid"]. "</td>";

        echo "<td>" . $row["status"]. "</td>";

        echo "</tr>";

    } 

    if($row["status"]=='Close') 

    {  // I want to count this value as 2        

    $count['close']++;

    echo "<tr>";

    echo "<td>" . $row["evaid"]. "</td>";

    echo "<td>" . $row["status"]. "</td>";

    echo "</tr>";

    } 

if($row["status"]=='Process') 

{  // I want to count this value as 2        

    $count['process']++;

    echo "<tr>";

    echo "<td>" . $row["evaid"]. "</td>";

    echo "<td>" . $row["status"]. "</td>";

    echo "</tr>";

}


}



print_r($count);


?>


查看完整回答
反對 回復 2022-05-27
  • 2 回答
  • 0 關注
  • 117 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號