2

Having trouble excluding data that is null, I just want to pull the rows that have discord_id data. Here is the code I have:

<?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);

?>
Mureinik
  • 297,002
  • 52
  • 306
  • 350
Zen
  • 77
  • 2
  • 7

4 Answers4

2

You have to use MySQL: IS NOT NULL like below:-

$result = mysqli_query($con,"SELECT * FROM `core_members` WHERE `discord_id` IS NOT NULL");
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
2

Add the following where clause to your code:-

where discord_id is not null

Full Select Statement:

SELECT * FROM core_members where discord_id is not null;
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
1

Add it as condition to the WHERE clause:

SELECT * FROM core_members where discord_id is not null
Jens
  • 67,715
  • 15
  • 98
  • 113
1

Just add an is not null condition:

$result = 
    mysqli_query($con, "SELECT * FROM core_members WHERE discord_id IS NOT NULL");
Mureinik
  • 297,002
  • 52
  • 306
  • 350