Jump to content

[SOLVED] Excluding blank rows when printing a table


ArizonaJohn

Recommended Posts

Hello,

 

The code below works great.  It prints out items in a MySQL database as an HTML table.  However, the database has entries where the first column (the variable "site") is blank.  How can I have this table exclude rows / entries where "site" is blank?

 

Thanks in advance,

 

John

 

$result=mysql_query("SHOW TABLES FROM database LIKE '$find'")
or die(mysql_error());


if(mysql_num_rows($result)>0){
while($table=mysql_fetch_row($result)){
print "<p class=\"topic\">$table[0]</p>\n";
$r=mysql_query("SELECT * , itemsa - itemsb AS itemstotal FROM `$table[0]` ORDER BY itemstotal DESC");



print "<table class=\"navbar\">\n";
while($row=mysql_fetch_array($r)){


$itemstotal = $row['itemsa'] - $row['itemsb']; 

print "<tr>";


print "<td class='sitename'>".'<a type="amzn" category="books" class="links2">'.$row['site'].'</a>'."</td>";

print "<td class='class1'>".'<span class="class1_count" id="class1_count'.$row['id'].'">'.number_format($itemstotal).'</span>'."</td>";
print "<td class='selector'>".'<span class="button" id="button'.$row['id'].'">'.'<a href="javascript:;" class="cell1" id="'.$row['id'].'">'.Select.'</a>'.'</span>'."</td>";
}
print "</tr>\n";
}
print "</table>\n";



}
else{
print "";
}

You can also filter them through the SELECT statement.  Depending on how site is stored

 

$r=mysql_query("SELECT * , itemsa - itemsb AS itemstotal FROM `$table[0]` WHERE site != '' ORDER BY itemstotal DESC");

 

or

 

$r=mysql_query("SELECT * , itemsa - itemsb AS itemstotal FROM `$table[0]` WHERE site IS NOT NULL ORDER BY itemstotal DESC");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.