douxuzui4590 2014-03-20 08:45
浏览 178
已采纳

为什么MySQL Query会跳过空值? 如何防止MySQL跳过NULL值?

I would like to know why MySQL Query serves different number of columns when some values in NULL or Zero(Integer Case).

For example, I have due as "0" integer (not sting - without Quotes) in some columns. When I make a query, I want to show "0" integer. But that column is skipped.

Can't it return just nothing instead of skipping the NULL value? How Can we overcome this error?

  $sql = "SELECT * FROM `2014-02-20`";
  $query = mysqli_query($con, $sql);
  $row = mysqli_fetch_assoc($query);

 while ($row = mysqli_fetch_assoc($query)){
    while ($this_item = current($row)) {
      echo key($row)."-->".$row[key($row)]."<br />";
      next($row);
    }
    echo "<br />";
  }


?>

I see different results like: Case 1 (with 0 in due column)

qty-->1
amount-->390

Case 2 (with some value in due)

activity-->sales
qty-->1
amount-->25500
  • 写回答

1条回答 默认 最新

  • dongyanzhui0524 2014-03-20 08:50
    关注

    Use foreach in the inner loop:

    while ($row = mysqli_fetch_assoc($query)){
        foreach($row as $key => $value) {
            echo "$key --> $value <br />";
        }
        echo "<br />";
    }
    

    A foreach loop will iterate through the whole $row array regardless of values that might evaluate to false.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 数字信号处理实验报告
  • ¥15 ensp路由器启动不了一直报#
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程