从mysql select中排除null数据

时间:2017-08-28 08:44:30

标签: php mysql sql select

排除数据为空的问题时,我只想拉出包含discord_id数据的行。这是我的代码:

<?php
$con=mysqli_connect("localhost","site","password","table");

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM core_members");

while($row = mysqli_fetch_array($result))
  {
  echo $row['name'] . " " . $row['discord_id']; 
  echo "<br />";
  }

mysqli_close($con);

?>

4 个答案:

答案 0 :(得分:2)

您必须使用下面的MySQL: IS NOT NULL: -

$result = mysqli_query($con,"SELECT * FROM `core_members` WHERE `discord_id` IS NOT NULL");

答案 1 :(得分:2)

在代码中添加以下where子句: -

discord_id不为空

完整选择声明:

SELECT * FROM core_members where discord_id is not null;

答案 2 :(得分:1)

将其作为条件添加到WHERE子句:

SELECT * FROM core_members where discord_id is not null

答案 3 :(得分:1)

只需添加is not null条件:

$result = 
    mysqli_query($con, "SELECT * FROM core_members WHERE discord_id IS NOT NULL");