Posted by needaticker on 09/30/93 11:26
Thanks for your help so far, I think that I'm getting there and have
come up with what follows which isn't working but maybe you can spot
what's wrong with it.
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");
$chooseall="SELECT * FROM tablename";
$chooseallresults=mysql_query($chooseall);
$numrows=mysql_numrows($chooseallresults);
$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();
?>
[Back to original message]
|