whats wrong with this php code?
The basics is that I have a table on the database that has a single
field (i have been trying some other stuff which includes an ID number
field but I wondered if anyone can help me fix the stuff below so I
don't need it).
The single field has about 100 entries so far but this will always
change and at some times there may be no entries (see the if / else
clause).
Otherwise I need to display a random entry from the table.
Here goes...
<?php
$username="dbusername";
$password="dbpassword";
$database="dbname";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM tablename";
$results=mysql_query($query);
$numrows=mysql_numrows($results);
$randget="SELECT * FROM tablename ORDER BY RAND() LIMIT 1";
$randgetresults=mysql_query($randget);
if ($numrows=0) {echo "Sorry no entries"
} else {
echo "$randgetresults";
mysql_close();
?>
If you can see anything wrong please let me know.
|