Jump to content

[SOLVED] I have no idea what else to do.


czukoman20

Recommended Posts

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

Link to comment
Share on other sites

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 :P

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.