Jump to content


Using ORDER BY statement


3 replies to this topic

#1 Tirus

    P2L Jedi

  • Members
  • PipPipPip
  • 764 posts
  • Gender:Male
  • Location:Montreal, Canada
  • Interests:Web Design, Programming, Music, Martial Arts

Posted 15 July 2006 - 07:41 PM

Hello all,

I am trying to have my results returned in alphabetical order BUT also ordered by a certain element.

To be more specific, for a business listings website, I want the listings that customers are paying for to show up first, followed by the regular unpaid listings, all of this in alphabetical order.

Right now, I am using

"order by intpaid desc"

intpaid meaning that the listing is a paid listing.

What happens with that coding is that the paid listings are listed above the unpaid listings but everything is not in alphabetical.

To see exactly what I mean, click on this link and enter Insurance - Life as the Category and AL as the state. Then press find. You will see my two test paid listings on top, but the results are not in alphabetical order.

How does one put them in alphabetical order? Does it involve using subqueries, something along the lines of ordering by intPaid in descending order after ordering by Business Name in descending order?

Any and all help would be greatly appreciated!

Tirus

#2 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 15 July 2006 - 07:55 PM

hers how i would do it.

i would create a mysql_query like so:
"select * from table where intpaid = 'true' order by [b]title_field[/b] asc

then a while loop to execute each row ( i think you already know how to to this :o )

then create a 2nd mysql_qeury:
"select * from table where intpaid = 'false' order by [b]title_field[/b] asc

then use that query in a while loop below the first loop!


..........................

or maybe theres a way to order by two fields.. i dont know...

#3 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 15 July 2006 - 08:02 PM

Its 2am, and im shattered to correct me if i am wrong which i may well be.....but..

ORDER BY field1, field2 ASC

Is that not possible? It rings a bell, but i'm really not sure on it.

TBH i'm so tired i dont understand a word you wrote lol!! Im just basing my post on...

"coolaid" said:

or maybe theres a way to order by two fields.. i dont know...

Edited by .Matt, 15 July 2006 - 08:03 PM.


#4 Tirus

    P2L Jedi

  • Members
  • PipPipPip
  • 764 posts
  • Gender:Male
  • Location:Montreal, Canada
  • Interests:Web Design, Programming, Music, Martial Arts

Posted 15 July 2006 - 08:33 PM

well, it seems that you can order by multiple columns as said here:

http://www.baycongro...e_reference.htm

i am trying it but it does not seem to be affecting the listings order...will keep trying.

EDIT: IT WORKS! IT WORKS!

thank you both very much, I just had to figure out the right combination of ASC DESC for the two column names (gets quite confusing).

Edited by Tirus, 15 July 2006 - 08:41 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users