如何使用mysql在php中停止空组

时间:2014-10-21 18:58:03

标签: php mysql

如何使用mysql

在php中停止空组

我想停止空行组

此代码显示如下

-----------------
                    <--- and this empty rows is showing empty group how to stop this
-----------------
UK
-----------------
UAE
-----------------
USA
-----------------

我想要这样

-----------------
UK
-----------------
UAE
-----------------
USA
-----------------

这是代码

<?php
    mysql_connect('localhost', 'user', 'password.') or die (mysql_error());
    mysql_select_db('phone') or die (mysql_error());
    $result = mysql_query("SELECT * from topdata GROUP BY model");
    //While there are rows to display
    while($row = mysql_fetch_array($result)){
    //Display the results from the current row and a line break
     echo  "<li><a href=../model/".urlencode($row['model']).".html>" .$row['model']."</a></li>";
    }
    ?>

1 个答案:

答案 0 :(得分:2)

<?php
mysql_connect('localhost', 'user', 'password.') or die (mysql_error());
mysql_select_db('phone') or die (mysql_error());
$result = mysql_query("SELECT * from topdata GROUP BY model");
//While there are rows to display
while($row = mysql_fetch_array($result))
{
 //Display the results from the current row and a line break
 if ( ! empty($row['model'])) // check if not empty
 {
    echo  "<li><a href=../model/".urlencode($row['model']).".html>" .$row['model']."</a></li>";
 }
}
?>