joerocket23
Weaksauce
- Joined
- Sep 15, 2007
- Messages
- 88
So I have a form that does all sorts of cool things after submission. One of the cool things it does is select a random entry from one table, but makes sure that the random selection has never been seen by the email address entered in the form. If someone enters the same email address everytime, they will never see the same random selection twice.
This is how I have tried to do it:
(I will eventually get rid of RAND() and use another method for random entry)
So I have this serialized array stored in a table linked with someones email address. When they enter their email address, it pulls that serialized array, unserializes it, then finds a random $id that is not in that array. Later in the code, it updates that array, serialzes it and updates it for that email address.
This works great when the form is submitted through PHP_SELF. However, if I had the exact same code in another page (action="page2.php"), it throws a warning about the datatype in the second arguement of in_array.
Exact same code, but it does not work when going through a different page.
If I print out the values such as $id and $var that are being operated on before the while statement, they are exactly as I would expect them to be.
Any suggestions?
Thanks,
Ryan
This is how I have tried to do it:
PHP:
if ($_SESSION['size'] = small){
$q= $db->query("SELECT id FROM small WHERE type = '$_POST[typeMe]' ORDER BY RAND()LIMIT 1");
while ($row =$q->fetchrow()) {$id = "$row[0]";}
$q= $db->query("SELECT seenMessages FROM records WHERE email = '$_POST[email]'");
while ($row =$q->fetchrow()) {$seenMessages = "$row[0]";}
$var = unserialize ($seenMessages);
//$id is the random message, compare versus $var...the array with all the previous messages for the given email address
while(in_array("$id", $var) == 1){
$q= $db->query("SELECT id FROM small WHERE type = '$_POST[typeMe]' ORDER BY RAND()LIMIT 1");
while ($row =$q->fetchrow()) {$id = "$row[0]";}
$q= $db->query("SELECT seenMessages FROM records WHERE email = '$_POST[email]'");
while ($row =$q->fetchrow()) {$seenMessages = "$row[0]";}
$var = unserialize ($seenMessages);
}
//get the info for the randomly selected ID
$q= $db->query("SELECT email, name, type, message FROM small WHERE id = '$id'");
*/
}
(I will eventually get rid of RAND() and use another method for random entry)
So I have this serialized array stored in a table linked with someones email address. When they enter their email address, it pulls that serialized array, unserializes it, then finds a random $id that is not in that array. Later in the code, it updates that array, serialzes it and updates it for that email address.
This works great when the form is submitted through PHP_SELF. However, if I had the exact same code in another page (action="page2.php"), it throws a warning about the datatype in the second arguement of in_array.
Exact same code, but it does not work when going through a different page.
If I print out the values such as $id and $var that are being operated on before the while statement, they are exactly as I would expect them to be.
Any suggestions?
Thanks,
Ryan