Jump to content

[SOLVED] Small Code Help


Ell20

Recommended Posts

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

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.