czukoman20 Posted July 2, 2009 Share Posted July 2, 2009 I've had this issue for a year now.. but finally went back to trying to fix it. RANDOM here is what i have $data = mysql_query("SELECT * FROM users WHERE category LIKE '%$category%' ORDER BY rand()") or die(mysql_error()); The problem I HAVE ALWAYS had was .. The ORDER BY rand() sux... What it does is it generates a random Order... but it will never generate a different random order after the first one.. its as if I am missing a refresh code that refreshes the rand() command. Help is greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/164458-solved-i-have-no-idea-what-else-to-do/ Share on other sites More sharing options...
pkedpker Posted July 2, 2009 Share Posted July 2, 2009 its always random man thats what random is! even though its not real random its just a mathematical equation of dividing a irrational result so therefore it can be cracked if the seed is found. you might try RAND(UNIX_TIMESTAMP()) which makes it much more harder.. but still cracked in online poker games but those were true hackers Quote Link to comment https://forums.phpfreaks.com/topic/164458-solved-i-have-no-idea-what-else-to-do/#findComment-867528 Share on other sites More sharing options...
czukoman20 Posted July 2, 2009 Author Share Posted July 2, 2009 I dont care if it gets hacked lol... its only used to randomly display listings on a pagination system, not to hide poker cards. The problem is .. ITS NOT ALWAYS RANDOM Its random once. For some reason my listings will display in a random order... but the exact same random order every time. thanks though .. it baffles me Quote Link to comment https://forums.phpfreaks.com/topic/164458-solved-i-have-no-idea-what-else-to-do/#findComment-867536 Share on other sites More sharing options...
.josh Posted July 2, 2009 Share Posted July 2, 2009 hmmm...are you like, pulling the results from the db and storing them in an array and paginating based on the array (array being stored in a session or flatfile)? Because if you are calling that on every page load, there's no reason it should not be returning different orders every time. Post more code. Quote Link to comment https://forums.phpfreaks.com/topic/164458-solved-i-have-no-idea-what-else-to-do/#findComment-867547 Share on other sites More sharing options...
schapel Posted July 2, 2009 Share Posted July 2, 2009 What happens to the $data variable after that line of code? Quote Link to comment https://forums.phpfreaks.com/topic/164458-solved-i-have-no-idea-what-else-to-do/#findComment-867549 Share on other sites More sharing options...
czukoman20 Posted July 2, 2009 Author Share Posted July 2, 2009 Ok.. I'll post the entire code Warning.... Its big.. <?php if (!(isset($pagenum))) { $pagenum = 1; } $data = mysql_query("SELECT * FROM users WHERE category LIKE '%$category%' ORDER BY rand()") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 10; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM users WHERE category LIKE '%$category%' $max ") or die(mysql_error()); while($values = mysql_fetch_array( $data_p )) { echo "";; $user = $values['username']; $company = $values['company_name']; $fname = $values['contact_firstname']; $lname = $values['contact_lastname']; $position = $values['contact_position']; $address = $values['address']; $city = $values['city']; $state = $values['state']; $zipcode = $values['zipcode']; $desc_mini = $values['description_mini']; $phone = $values['contact_direct_phone_normal']; if($session->logged_in) { $sub = "submit2.php"; }else{ $sub = "submit2.php"; } $types = array("jpg","gif","png","swf"); $dir = dirname(__FILE__)."/site-images/searchlogos/"; foreach($types as $type) { if(file_exists($dir.$user."_logo.".$type)) { {?> HTML PAGINATED DATA I removed due to the bulk of the listing. <?php} } } } echo ""; echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } ?> mmm...are you like, pulling the results from the db and storing them in an array and paginating based on the array (array being stored in a session or flatfile)? Because if you are calling that on every page load, there's no reason it should not be returning different orders every time. Post more code. Its basically an array, i am not sure if its a session or flat file because one of my friends helped me write this code. Quote Link to comment https://forums.phpfreaks.com/topic/164458-solved-i-have-no-idea-what-else-to-do/#findComment-867863 Share on other sites More sharing options...
czukoman20 Posted July 3, 2009 Author Share Posted July 3, 2009 Thats exactly what happened when i tried the question in other forums.. I posted the code, and then Nothing..... anybody out there? Quote Link to comment https://forums.phpfreaks.com/topic/164458-solved-i-have-no-idea-what-else-to-do/#findComment-868526 Share on other sites More sharing options...
.josh Posted July 3, 2009 Share Posted July 3, 2009 okay so the problem is that you are NOT ordering your results randomly. Not even the first time. You have 2 queries in that script. The first one you have order by rand() but that's pointless since all you are doing with it is finding out the row count for your pagination. It's the 2nd query that you need to order by rand(), as that's the one you are actually getting the data from. Quote Link to comment https://forums.phpfreaks.com/topic/164458-solved-i-have-no-idea-what-else-to-do/#findComment-868547 Share on other sites More sharing options...
czukoman20 Posted July 8, 2009 Author Share Posted July 8, 2009 Ok i'll give that a try Quote Link to comment https://forums.phpfreaks.com/topic/164458-solved-i-have-no-idea-what-else-to-do/#findComment-871293 Share on other sites More sharing options...
czukoman20 Posted July 8, 2009 Author Share Posted July 8, 2009 THANK YOU soooo much! Quote Link to comment https://forums.phpfreaks.com/topic/164458-solved-i-have-no-idea-what-else-to-do/#findComment-871301 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.