jas4 Posted April 19, 2007 Share Posted April 19, 2007 basically I am performing a query linked to a database (looking for products in a catalogue) and if there are no products, i want to display a message saying there are no products, but if there are products i want to display them. I have tried a few variations but nothing seems to work. any advice appreciated $query='SELECT * FROM diet_food'; $results=mysql_query($query) or die(mysql_error()); iif (!empty($query)){ while ($row = mysql_fetch_assoc($results)) { extract($row); echo '<div class="thumbnail">'; echo " <a href='getproddietfood.php?prodid=" . $id ."'><img src='images/shopItems.gif' alt='' width='65' height='90'></a>"; echo ' <p><h2>',$name,'</h2>'; echo'</div>'; } else {echo "Sorry";} } Quote Link to comment Share on other sites More sharing options...
trq Posted April 19, 2007 Share Posted April 19, 2007 An example. <?php $sql = "SELECT * FROM foo"; // execute the query. if ($result = mysql_query($sql)) { // check for results. if (mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { // echo results. } } else { echo "No results found"; } } else { echo "Query failed\n$sql\n" . mysql_error(); } ?> Quote Link to comment Share on other sites More sharing options...
jas4 Posted April 19, 2007 Author Share Posted April 19, 2007 ok its looking much better now, but still not properly working. I've modified it slightly to fit round my code to this: $query='SELECT * FROM f_equip'; $results=mysql_query($query) or die(mysql_error()); // execute the query. if ($results = mysql_query($query)) { // check for results. if (mysql_num_rows($results)) { while($row = mysql_fetch_assoc($results)) { extract($row); echo '<div class="thumbnail">'; echo " <a href='getproddietfood.php?prodid=" . $id ."'><img src='images/shopItems.gif' alt='' width='65' height='90'>"; echo ' <p><h2>',$name,'</h2>'; echo'</div>'; } } } else { echo "<div id='noShopItems'><h2><br><br>There are currently no food supplement products in stock, <br> please check back later.<h2></div>"; } } else { echo "Query failed\n$query\n" . mysql_error(); } if there are no products then it works fine, however if there are products found there is nothing displayed. thanks for that first reply Quote Link to comment Share on other sites More sharing options...
jas4 Posted April 19, 2007 Author Share Posted April 19, 2007 sorry there was a flaw in the code -- PROBLEM SOLVED! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.