PHP – 打印表时排除空行
发布时间:2020-12-13 21:34:48 所属栏目:PHP教程 来源:网络整理
导读:下面的代码效果很好.它将 MySQL数据库中的项目打印为HTML表格.但是,数据库具有第一列(变量“site”)为空的条目.如何让此表排除“site”为空的行/条目? $result=mysql_query("SHOW TABLES FROM database LIKE '$find'")or die(mysql_error());if(mysql_num_r
下面的代码效果很好.它将
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 ""; } 解决方法
在SQL查询中添加where子句.
WHERE `site` <> '' or WHERE `site` != '' 应该管用. 但是,如果您希望其他PHP选项的站点为空的行,那么最好过滤掉PHP中的空白站点而不是MySQL查询. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |