olilish Posted March 4, 2010 Share Posted March 4, 2010 Hello, I have a problem with If Else.I would like a simple 'no new records' message to be displayed if no new records have been added.This is my code.-----------------------------------------------------$result = mysql_query("SELECT * FROM pages WHERE approved='0' ORDER BY id DESC");if ($result==NULL){echo "<p>No new Testimonials</p>";}else {while($row = mysql_fetch_array($result)) {*and this is where i echo my results* }}----------------------------------------------------So, when there are no new records or records WHERE approved = '0', I would just like a simple - No new records echo.I do not get any error message, but my echo does not show up.Any help would be superb!!THanks. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 4, 2010 Share Posted March 4, 2010 The return value from mysql_query is never going to be null. You can use mysql_num_rows to determine how many rows the query returned. Link to comment Share on other sites More sharing options...
olilish Posted March 6, 2010 Author Share Posted March 6, 2010 So, if no rows are returned then can I use that in my if/else to echo 'no new testimonials' ? Link to comment Share on other sites More sharing options...
thescientist Posted March 6, 2010 Share Posted March 6, 2010 should work. give it a try and report back. Link to comment Share on other sites More sharing options...
olilish Posted March 8, 2010 Author Share Posted March 8, 2010 mmm, this works but it doesn't really help.I need to be able to determine if there are any records that have a value of '0' in my approved field.If there are none, then echo no new testimonials.So how do I query for 'are there any 0's ' ?? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 8, 2010 Share Posted March 8, 2010 That's exactly what your query is doing.SELECT * FROM pages WHERE approved='0' ORDER BY id DESC Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.