Forum Moderators: coopster

Message Too Old, No Replies

Displaying table contents

         

ffoeg

1:05 pm on Apr 25, 2006 (gmt 0)

10+ Year Member



Heya. I'm trying to display the content contained within a table on my mysql database. What I want it to do is to check whether there is anything stored within the table. If not, it will display a message saying that there is nothing stored in it. If there is something stored, then it will display the contents of the table.

This is the code that I have so far:


$result = mysql_query ("SELECT url,name,date FROM links");
while($row = mysql_fetch_array($result)) {
if (($row['url'] == NULL) ¦¦ ($row['name'] == NULL)) {
echo "There are no links stored in the database yet.";
}
else {
echo "<p><a href=\"http://{$row['url']}\" target=\"_blank\">{$row['url']}</a><br />"."Posted by: {$row['name']} on {$row['date']}</p>";
}
}

Any help would be appreciated. Is there any way to check if something is null or not?

eelixduppy

1:11 pm on Apr 25, 2006 (gmt 0)



Hello...

i would do something like this:

$result = mysql_query ("SELECT url,name,date FROM links");
$num_of_rows = mysql_num_rows($result);
if ($num_of_rows == 0) {
echo "There is no data";
}
else {
while($row = mysql_fetch_array($result)) {
echo "<p><a href=\"http://{$row['url']}\" target=\"_blank\">{$row['url']}</a><br />"."Posted by: {$row['name']} on {$row['date']}</p>";
}

Hope this helps

eelix

ffoeg

4:54 pm on Apr 25, 2006 (gmt 0)

10+ Year Member



Woohoo! It worked! Thanks so much :)