PowWeb Forums - The Perfect Community for the Perfect Host  

Register now to interact with over 11,000 members! Registered users have Posting Privileges, free access to Private Messaging, Email Notifications and more.

Go Back   PowWeb Community Forums > The PowWeb Platform > MySQL
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Closed Thread
 
Thread Tools Search this Thread
Old 1-4-05, 04:06 PM   #1
zimmer3
 
Posts: n/a
Sorting after getting MYSQL Results

Hello,

I have a database of Books. I currently use a SQL to get the 4 newest additions, and then another SQL to list in alphabetic order by title All books.

My problem is that the 4 newest books also show up in the alpha list. I would like to do away with the second SQL statement, and make my alpha list from the entries remaining from the first SQL statement.

How can I do this? How do I sort the remaining results to alpha?

Thanks !
 
Old 1-5-05, 11:14 AM   #2
zimmer3
 
Posts: n/a
No one's got any ideas?
 
Old 1-5-05, 12:14 PM   #3
mitchind
Older not wiser
 
mitchind's Avatar
 
Join Date: Nov 2003
Location: Calgary, AB
Posts: 2,473
Reputation: 205
This would work fine as a subquery (not available until Powweb upgrades to MySQL 4.1)

But since you have to run the two queries anyways, it kind of defeats the purpose. You might as well read the results of the first query into a comma-delimited string - then use that to exclude titles from the second query.

Don't know how much PHP you have under your belt, but maybe a little pseudo-code will help for now.

PHP Code:
$query1 "SELECT titleID, title from titles ORDER BY titleID DESC LIMIT 0,3"

Loop to build comma-delimited list of titleID from $query1 results ...
$lasttitles = "12,11,10,9"

PHP Code:
$query2 "SELECT titleID, title from titles WHERE titleID NOT IN (" $lasttitles ") ORDER BY title"
mitchind is offline  
Old 1-5-05, 03:47 PM   #4
zimmer3
 
Posts: n/a
>> NOT IN

That did the trick, never heard of that one. Thanks !
 
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 11:57 AM.


Contents ©PowWeb, Inc. ~ vBulletin, Copyright © 2000-2007 Jelsoft Enterprises Limited.