I noticed that when I loaded this page several times... each more than 30 sec apart several times I would get the same joke back from the RAND function...
There are two things I can sudgest to combat this.. you can add something to the WHERE clause... and id <> (current id)
Or you can try to seed the RAND() function. I know in the php manual there was some mention of using the RAND() with ORDER BY, but what you are doing now is ok.
NOTE: you probably will want to add back the WHERE validation = 'yes'.. I removed that becasue I did not notice this field when I first setup my db...
Try this...
<?php
//connect to db
$db = mysql_connect("localhost","","");
mysql_select_db("") or die ("could not select database");
//select the joke id and the time to copare
$sql = "SELECT uj.id, uj.joke, jod.time FROM userjokes uj, jokeofday jod WHERE uj.id = jod.id";
$result=mysql_query($sql, $db);
$row = mysql_fetch_assoc($result);
//compare the time in the db against the 24 hour limit
if ((time() - $row["time"]) > 30)
{
echo("<br>here<br>");
//select a new random joke
$query = "SELECT * FROM joke WHERE validation='yes' and id <> " . $row["id"] . " ORDER by RAND() LIMIT 1";
//$query = "SELECT * FROM userjokes ORDER by RAND() LIMIT 1";
$resultat=mysql_query($query, $db);
$roww = mysql_fetch_assoc($resultat);
//make the id easir to read
$id=$roww["id"];
//put the id into the table that holds the id and time
$request = "UPDATE jokeofday SET id = " . $id . ", time = " . time();
mysql_query($request, $db);
$query = "SELECT joke FROM userjokes, jokeofday WHERE userjokes.id = jokeofday.id";
$result=mysql_query($sql, $db);
$row = mysql_fetch_assoc($result);
}
echo $row["joke"];
?>
I changed two of the queries hopefully this will eliminate the selecting of the same joke back to back...
PHPdev