Hi, there's no 'logic' error at all that I can see. It's more a design error as it doesn't do the job the way that you describe it at all. What actually happens is that the starting HTML (heading and table start) is output before the database is even contacted, so there's no way for you to take the table back if you don't receive any relevant hits. try something more like this: <?php // database information $host = 'xxx'; $user = 'xxx'; $password = 'xxx'; $dbName = 'xxx'; mysql_connect(localhost,$user,$password); @mysql_select_db($dbName ) or die( "Sorry But There Seems To Be A Problem Connecting To The Database"); $query="SELECT * FROM shop"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); if ($num) { ?> <h2>Your favorites search result</h2><div>You are here: index.htm Home > Your favorites</div> <div class="internalContentArea sgtable "> <div class="tableHead">Sub-category search result</div> <div> <table width='100%' id='table1' cellspacing="0"><thead><tr> <th scope="col">Shop name</th> </tr></thead><tbody> <?php $i=0; while ($i < $num) { $shopname=mysql_result($result,$i,"shopname"); echo " <tr> <td>$shopname</td> </tr>"; $i++; } ?></tbody></table> index.htm < Back to search <div> </div> } else { echo " <div> <div class='alert'>The search criteria you entered did not generate any result, index.htm please try again .</div> </div>"; } You'll probably need to polish this some, because I quickly cut/pasted it before I go down the pub. Niel -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php