标签: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 "
$table[0]
\n";$r=mysql_query("SELECT * , itemsa - itemsb AS itemstotal FROM `$table[0]` ORDER BY itemstotal DESC");
print "
while($row=mysql_fetch_array($r)){
$itemstotal = $row['itemsa'] - $row['itemsb'];
print "
";print "
".' '.$row['site'].''."";print "
".' '.number_format($itemstotal).''."";print "
".' '."";}
print "
\n";}
print "
\n";}
else{
print "";
}
解决方法:
在SQL查询中添加where子句.
WHERE `site` <> ''
or
WHERE `site` != ''
应该管用.
但是,如果您希望其他PHP选项的站点为空的行,那么最好过滤掉PHP中的空白站点而不是MySQL查询.
标签:php
来源: https://codeday.me/bug/20190730/1584556.html