ArizonaJohn Posted July 15, 2009 Share Posted July 15, 2009 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 ""; } Quote Link to comment https://forums.phpfreaks.com/topic/166093-solved-excluding-blank-rows-when-printing-a-table/ Share on other sites More sharing options...
rhodesa Posted July 15, 2009 Share Posted July 15, 2009 while($row=mysql_fetch_array($r)){ if(empty($row['site'])) continue; Quote Link to comment https://forums.phpfreaks.com/topic/166093-solved-excluding-blank-rows-when-printing-a-table/#findComment-875944 Share on other sites More sharing options...
J.Daniels Posted July 15, 2009 Share Posted July 15, 2009 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"); Quote Link to comment https://forums.phpfreaks.com/topic/166093-solved-excluding-blank-rows-when-printing-a-table/#findComment-875957 Share on other sites More sharing options...
ArizonaJohn Posted July 15, 2009 Author Share Posted July 15, 2009 As they say in Mexico, Gracias. It works Quote Link to comment https://forums.phpfreaks.com/topic/166093-solved-excluding-blank-rows-when-printing-a-table/#findComment-875989 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.