0

how to stop empty group in php using mysql

i want to stop empty rows group

this code is showing like this

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

and i want like this

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

this is code

<?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>";
    }
    ?>
user1796164
  • 131
  • 1
  • 4
  • 14
  • Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). [This article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide. – Jay Blanchard Oct 21 '14 at 19:06

1 Answers1

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>";
 }
}
?>
Paul Denisevich
  • 2,329
  • 14
  • 19