Ell20 Posted October 25, 2007 Share Posted October 25, 2007 Hey, Im currently trying to produce some code which displays the 3 latest news items followed by a link to Read More = Working fine. However I also wanted to display a message saying if there are no news messages then echo "No news yet". Here is my code: <?php $query = "SELECT * FROM news WHERE club_id = '$club_id' ORDER BY 'news_id' DESC LIMIT 3"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { echo "<b>Title: </b>" ; echo $row['title']; ?> <hr> <?php } ?> <a href='news.php'>Read More</a> <br> <?php if ($row == 0) { echo "No news yet"; } ?> When I use this code the message "No news yet" is always there whether there is news or not. Appreciate any help Cheers Quote Link to comment https://forums.phpfreaks.com/topic/74793-solved-small-code-help/ Share on other sites More sharing options...
premiso Posted October 25, 2007 Share Posted October 25, 2007 <?php $query = "SELECT * FROM news WHERE club_id = '$club_id' ORDER BY 'news_id' DESC LIMIT 3"; $result = mysql_query($query); $rows = mysql_num_rows($result); while ($row = mysql_fetch_assoc($result)) { echo "<b>Title: </b>" ; echo $row['title']; ?> <hr> <?php } ?> <a href='news.php'>Read More</a> <br> <?php if ($rows < 1) { echo "No news yet"; } ?> Should fix it. Since $row was an array that was not a valid check. www.php.net/mysql_num_rows Quote Link to comment https://forums.phpfreaks.com/topic/74793-solved-small-code-help/#findComment-378154 Share on other sites More sharing options...
sasa Posted October 25, 2007 Share Posted October 25, 2007 try <?php if (mysql_num_rows($result) == 0) { echo "No news yet"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74793-solved-small-code-help/#findComment-378156 Share on other sites More sharing options...
Ell20 Posted October 25, 2007 Author Share Posted October 25, 2007 Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/74793-solved-small-code-help/#findComment-378165 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.