Skip to content
Advertisement

How to ignore all fields which are empty in pic column?

All with empty fields in pic column should be ignored. (Even Name/Address shouldn’t be visible)

$sql = "SELECT pic, title, address FROM 
 WP_2344432";  
$result = $conn->query($sql);  
if ($result->num_rows > 0) { // output data of 
   each row  
  while($row = $result->fetch_assoc()) {  
     echo '<br> <img src="'.$row['pic'].'"><br>Name: '. 
     $row['title']. '<br>Coordinates: ' . $row['address'] . 
      '<br>';  
   }  
 } else {
   echo "0 results"; 
}

Advertisement

Answer

If the pic column contains null then add WHERE pic IS NULL to your select. If it is simply empty then use WHERE pic = ''.

$sql = "SELECT pic, title, address FROM WP_2344432 WHERE pic IS NOT NULL"; 

or

$sql = "SELECT pic, title, address FROM WP_2344432 WHERE pic != ''"; 
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement