MySQL Forums
Forum List  »  PHP

help needed with a bit of PHP
Posted by: max wifi
Date: September 10, 2005 10:49PM

The code below prints out a random entry from a table in a database. Or if the table is empty it prionts "sorry no entries".

My problem is, that in the first instance it prints more than just the random entry:

This pretty much does what I need it to but it adds some code in the
result. (I mean instead of just showing the "random entry", it shows
"Array ( [field] => random entry )".

It would be great if I could get
rid of all the other stuff. Here's my code so far. Can anyone tidy up
my result to get it to do what I want it to?

Thanks

<?php
$username="username";
$password="password";
$database="database";

mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$randgetq=mysql_query("SELECT * FROM tablename ORDER BY RAND() LIMIT
1");

if (!$randgetresults=mysql_fetch_array($randgetq, MYSQL_ASSOC))
{
echo "Sorry no entries";

}

else
{
print_r($randgetresults);
}

mysql_close();
?>

Options: ReplyQuote


Subject
Written By
Posted
help needed with a bit of PHP
September 10, 2005 10:49PM
September 20, 2005 11:43PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.