Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.