jeorocket Posted March 25, 2009 Share Posted March 25, 2009 Hi, 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: 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); } (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, 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 Link to comment https://forums.phpfreaks.com/topic/151001-function-works-when-using-php_self-but-not-through-another-page/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.