[ale] recommend a good PHP/MYSQL list?

George Carless kafka at antichri.st
Fri Apr 18 17:22:23 EDT 2003


Hi Drew,

It's a little bit tricky - and your best bet would probably be to just 
re-sort in PHP, as you suggest (it's fairly simple to do, as it 
happens).  Alternatively, the latest version(s) of MySQL do support 
sub-selects, so you could use that.

If you want to sort in PHP, just grab the whole result set into an Array, 
and then use the array_multisort() function.

To grab everything into an array, you could use:

foreach ($result as $row) { $resultarray[$count++] = $row; }

Then, assuming that your first field is the key on which you want to sort:

$resultarray = array_multisort($resultarray,SORT_ASC);

I think that's about right.  Hope it helps.

--George

At 04:05 PM 4/18/2003 -0500, you wrote:
>Nah. What I am trying to do is more complex. The closest thing I could 
>find is
>like a cross between a subselect and a sort:
>/*
>http://www.mysql.com/doc/en/ANSI_diff_Sub-selects.html
>http://www.mysql.com/doc/en/Sorting_rows.html
>*/
>
>I want to select random records from the table AND list the result order 
>by id
>DESC;
>Without throwing the data into an array (cause I really don't know how :)).
>Something like this:
>
>///
>$sql="select value from table order by rand(), order by id desc limit 20";
>$result=mysql_query($sql);
>while ($myrow=mysql_fetch_array($result))
>{
>$value=$myrow["value"];
>printf ("value");
>///
>
>(So take 20 random rows -of the 1000 that exist- AND order by id DESC)
>I am thinking someone would suggest grabbing the random records and sorting
>them in the while array somehow. But that is over my head (which is why I
>turned to the mySQL queries). I couldn't find that concept in the manual.
>
>Drew
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>On Fri April 18 2003 15:34, F. Grant Robertson wrote:
> > Mysql can return random rows..  or you could generate psuedo random numbers
> > and query by WHERE IN (1,2,3,4,5)
> >
> > Take a look at the mysql manual..
> >
> > http://www.mysql.com/doc/en/index.html
> >
> > -G
> >
> >
> > -----Original Message-----
> > From: ale-admin at ale.org [mailto:ale-admin at ale.org]On Behalf Of
> > ChangingLINKS.com
> > Sent: Friday, April 18, 2003 4:05 PM
> > To: ale at ale.org
> > Subject: [ale] recommend a good PHP/MYSQL list?
> >
> >
> > 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





More information about the Ale mailing list