[ale] recommend a good PHP/MYSQL list?

George Carless kafka at antichri.st
Fri Apr 18 17:52:13 EDT 2003


Why go to all of that trouble, when you could just sort the array after the 
event?

--George

At 05:50 PM 4/18/2003 -0400, you wrote:
>This might help you in the right direction.
>
>- mike
>
><?
>// First seed rand()
>srand((double)microtime()*1000000);
>
>// Load up pri_keys
>$sql = "SELECT pri_key FROM table_name";
>$ret = mysql_query($sql);
>
>// MYSQL_ASSOC is important, if you have a table with 3 million keys,
>// and omit MYSQL_ASSOC or MYSQL_NUM (the one for non-assoc arrays)
>// then you have an array of 6 million, whereas if you use either
>// ASSOC or NUM you get an array half that size.  Important for large
>// apps.
>while($row = mysql_fetch_array($ret, MYSQL_ASSOC))
>{
>   $keys[] = $row['pri_key'];
>}
>
>// Loop thru max number of rows you want to grab
>$start = 0;  // Stays at zero
>$max   = 10; // Maximum number of rows to grab
>$num_keys = sizeof($keys);
>
>$sql = 'SELECT cols FROM table_name WHERE ';
>
>while($start < $max)
>{
>   $tmp_key = $keys[rand(0,$num_keys)];
>
>   if($start != ($max-1))
>   {
>      $sql .= ' pri_key='.$tmp_key.' OR';
>   }
>   else
>   {
>      $sql .= ' pri_key='.$tmp_key;
>   }
>}
>
>$sql .= ' ORDER BY somthing DESC';
>
>$ret = mysql_query($sql);
>
>// Do your stuff now...
>
>?>
>On Fri, 2003-04-18 at 16:05, ChangingLINKS.com wrote:
> > That php-ale list hasn't materialized yet, and I am not thinking I 
> should post
> > lots of php questions (though it would be a positive offset to the flame
> > battles that arise).
> >
> > Can someone recommend a great php list (from experience)?
> >
> > I am trying to grab random records from a mysql database and put them 
> in order
> > desc by primary key in one query.
> > --
> > Wishing you Happiness, Joy and Laughter,
> > Drew Brown
> > http://www.ChangingLINKS.com
> > _______________________________________________
> > Ale mailing list
> > Ale at ale.org
> > http://www.ale.org/mailman/listinfo/ale
> >
>
>
>_______________________________________________
>Ale mailing list
>Ale at ale.org
>http://www.ale.org/mailman/listinfo/ale

_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale





More information about the Ale mailing list