3 php
下面的代码效果很好.它将MySQL数据库中的项目打印为HTML表格.但是,数据库具有第一列(变量"site")为空的条目.如何让此表排除"site"为空的行/条目?
$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 "";
}
Run Code Online (Sandbox Code Playgroud)
在SQL查询中添加where子句.
WHERE `site` <> ''
or
WHERE `site` != ''
Run Code Online (Sandbox Code Playgroud)
应该管用.
但是,如果您希望其他PHP选项的站点为空的行,那么最好过滤掉PHP中的空白站点而不是MySQL查询.
| 归档时间: |
|
| 查看次数: |
1449 次 |
| 最近记录: |