Irish SEO,  Marketing & Webmaster Discussion

 

SQL Query

This is a discussion on SQL Query within the Coding Help forums, part of the Webmaster Help category; I have this query below: Code: $sql = "SELECT id,name,date FROM releases WHERE date>='".date("Y-m-d")."' ORDER BY date ASC LIMIT ".$limit.""; ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help

Register Forum Rules FAQDonate Members List Calendar Search Today's Posts Mark Forums Read


Notices

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 23-08-2007, 08:12 PM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 410
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ziycon will become famous soon enough
Send a message via MSN to ziycon Send a message via Skype™ to ziycon
Default SQL Query

I have this query below:
Code:
$sql = "SELECT id,name,date FROM releases WHERE date>='".date("Y-m-d")."' ORDER BY date ASC LIMIT ".$limit."";
It displays anything thats equal or in the future of the current date. But say i have 10 results on screen and five are the date 24-08-2007 and five are the date 28-08-2007, they are grouped together which is fine.

Now what im trying to do which wont work for me is to take the five '24' dated ones and order from a-z and then the five '28' ones and order from a-z like below:

24-08-2007 a
24-08-2007 c
24-08-2007 h
24-08-2007 m
24-08-2007 q
28-08-2007 d
28-08-2007 i
28-08-2007 o
28-08-2007 r
28-08-2007 w

Can anyone see where im going wrong?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 23-08-2007, 08:18 PM
daviddoran's Avatar
Wannabe Geek
Recent Blog: iMSISS
 
Join Date: Aug 2006
Location: Meath, Ireland
Posts: 342
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
daviddoran will become famous soon enough
Default

Well taking the a-z column as "LETTER" you would do this:

$sql = "SELECT id,name,date FROM releases WHERE date>='".date("Y-m-d")."' ORDER BY date ASC, LETTER ASC LIMIT ".$limit."";
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 23-08-2007, 09:01 PM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 410
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ziycon will become famous soon enough
Send a message via MSN to ziycon Send a message via Skype™ to ziycon
Default

Quote:
Originally Posted by daviddoran View Post
Well taking the a-z column as "LETTER" you would do this:

$sql = "SELECT id,name,date FROM releases WHERE date>='".date("Y-m-d")."' ORDER BY date ASC, LETTER ASC LIMIT ".$limit."";
Sorry, i was really clear there, they aren't just letters, there strings but i want them from a-z based on the first character of the string, if you get me?!?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 23-08-2007, 09:04 PM
daviddoran's Avatar
Wannabe Geek
Recent Blog: iMSISS
 
Join Date: Aug 2006
Location: Meath, Ireland
Posts: 342
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
daviddoran will become famous soon enough
Default

Ok, don't know how I missed the name column in the query!

Well surely the query would be this then: (simply order by date, then order by name alphabetically)

$sql = "SELECT id,name,date FROM releases WHERE date>='".date("Y-m-d")."' ORDER BY date ASC, name ASC LIMIT ".$limit."";
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 23-08-2007, 09:22 PM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 410
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ziycon will become famous soon enough
Send a message via MSN to ziycon Send a message via Skype™ to ziycon
Default

Thanks david, i was using the query below with the 'AND' statement which was messing up the results, thanks again.

Code:
 $sql = "SELECT id,name,date FROM releases WHERE date>='".date("Y-m-d")."' ORDER BY date ASC AND name ASC LIMIT ".$limit."";
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
query, sql

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Contract and Resignation Query Cormac The Business Aspects of Web Work 4 04-10-2007 10:12 AM
More powerful server... how much faster will my SQL queries be? dude Server / Technical Administration Tips and Queries 14 13-08-2007 09:45 AM
MS SQL Web Interfaces? blacknight Server / Technical Administration Tips and Queries 12 09-03-2007 10:48 AM
Importing XML files into MS SQL davidbehan Coding Help 0 06-02-2007 06:00 PM
MS SQL Tutorials / Resources blacknight Server / Technical Administration Tips and Queries 0 17-01-2007 10:09 AM


Sponsored links

Paid On Results


All times are GMT +1. The time now is 05:08 AM.


Powered by: vBulletin Version 3.7.3, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Hosted in Ireland by Blacknight - Test your ISP |Irish Hosting Directory| Armchair.ie|Logo by Eden Web Design|Avatars by Afterglow |Latest Blog Entries | VPS HostingAd Management by RedTyger

Search Engine Friendly URLs by vBSEO 3.2.0