Using Dreamweaver CS5 / MySQL
I'm trying to set up a query that will display rows of data but only if a specific column has data in it. If the Charname column is blank I don't want that row to be displayed.
Currently the query works, but it also displays the rows when the Charname column is empty. I'm struggling to set up and have failed at every turn to do it. Thanks in advance.
mysql_select_db($database_login_form, $login_form);
$query_Recordset1 = "SELECT * FROM users";
$Recordset1 = mysql_query($query_Recordset1, $login_form) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
<?php do { ?>
<li><a href="profile.php?id=<?php echo $row_Recordset1['id']; ?>"><?php echo $row_Recordset1['Charname']; ?></a></li>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
You could use COALESCE()
to treat blank (empty string) and NULL
as the same thing:
SELECT * FROM users WHERE COALESCE(Charname, '') != ''
You never told us what "empty" actually means, but a good guess would be empty string or NULL
.
update your query like this
SELECT * FROM users where Charname IS NOT NULL or Charname != '';
you can also use COALESCE()
for check null
SELECT * FROM users WHERE COALESCE(Charname, '') != '';
for more information
https://www.w3schools.com/sql/sql_isnull.asp
and you can aslo check in your php end
suppose like this
$Charname = $row_Recordset1['Charname'];
if($Charname == '' || $Charname === null || is_null($Charname)){
continue;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With