【问题标题】:in MYSQL, get only those columns that have values that are the same在 MYSQL 中,只获取那些具有相同值的列
【发布时间】:2015-08-21 22:23:58
【问题描述】:

我有一张表格,显示用户在布尔值中的拼图片段...

client   |  col A | col B | col C | col D | col E
john Doe |    1   |   1   |   0   |   0   |   1
Jane Deer|    0   |   1   |   0   |   1   |   0

我可以从 Db 中获取该行。

// Get puzzle pieces
$requery = "SELECT * FROM puzzletbl WHERE client_id = '$client_id' LIMIT 1";
$reresult = mysqli_query($dbc, $requery);

// Check for missing pieces
if ($reresult){
    while ($row = mysqli_fetch_array($reresult, MYSQLI_ASSOC)) {
        $status = array("NO", "OKAY");

    } // END WHILE
} // END  IF REresult

我只需要获取那些带有 0 的列(它们缺少部分),因此我可以将其添加到电子邮件中,让他们知道缺少什么。

【问题讨论】:

    标签: php mysql arrays


    【解决方案1】:

    循环遍历$row,测试值是否为0

    while ($row = mysqli_fetch_array($reresult, MYSQLI_ASSOC)) {
        $zero_cols = array();
        foreach ($row as $col => $val) {
            if ($col == "client") {
                $client = $val;
            } elseif ($val == 0) {
                $zero_cols[] = $col;
            }
        }
        // Send mail to $client with $zero_cols info
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多