Buy Sell Discuss UK Domain Names at AcornDomains.co.uk Domain Monster Domain Name Registration

Today's Drop Dates are: 19-02-2012 or 26-02-2012   All times are GMT. The time now is 01:31:25 PM.
Domain Name Sales Domain Software Calculate UK Domain Drop Dates Domain Registration NameDrive Domain Parking Subscribe to our Domains For Sale newsletter
Go Back   Domain Forum Acorn Domains Buy Sell Auction UK Domains > Website Design and Promotion > Website Design
Connect with Facebook

Website Design Discuss web design

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 03-07-2007, 03:39:05 PM     #1 (permalink)
Administrator
 
admin's Avatar
 
Join Date: Jun 2004
Posts: 8,601
admin has disabled reputation

MySql Select statement help please

I am working on DomainPrices.co.uk and want to sort the domain list by month, trouble is, when I do so, the SQL reads it as text and sorts it alphabetically and not by month as required. So I guess i need to change how I enter the month data for this to work, what's the best way?

This is the SQL query code I am using:
Code:
$sql = mysql_query("SELECT * FROM `item` ORDER BY `Month` ASC");
admin is offline  
Old 03-07-2007, 03:44:58 PM     #2 (permalink)

 
Join Date: May 2007
Posts: 1,148
monaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond repute

If Month is a string, then the sort is working correctly, why not store Month as an integer or have a generic datetime rather than a seperate month field?
__________________
Alex Monaghan - Drop Catch & Drop Lists - PM for details
Online Accounting|Pine Furniture|Barbie
monaghan is offline  
Old 03-07-2007, 03:58:43 PM     #3 (permalink)

 
bb99's Avatar
 
Join Date: Mar 2005
Posts: 1,547
bb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond repute

You could do it two ways:

a) Change all the months to numbers (but you can do it relatively quickly by saying " update 'item' set 'month' = '01' where 'month' = 'January' " etc).

b) Setup another table with two fields - monthnumber and monthtext - so it's "01", "January" blah blah "12", "December" and then do a cleverer query statement that links the month text to the number in your second table.
bb99 is offline  
Old 03-07-2007, 04:00:45 PM     #4 (permalink)
Administrator
 
admin's Avatar
 
Join Date: Jun 2004
Posts: 8,601
admin has disabled reputation

Quote:
Originally Posted by monaghan View Post
why not store Month as an integer or have a generic datetime rather than a seperate month field?
How do I do that? Sorry I am a novice at this
admin is offline  
Old 03-07-2007, 04:04:31 PM     #5 (permalink)

 
Join Date: May 2006
Posts: 1,188
Jeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond repute

Quote:
Originally Posted by bb99 View Post
a) Change all the months to numbers (but you can do it relatively quickly by saying " update 'item' set 'month' = '01' where 'month' = 'January' " etc).
that is going to be the easiest way - 12 queries will update it all
Jeewhizz is offline  
Old 03-07-2007, 04:08:51 PM     #6 (permalink)

 
bb99's Avatar
 
Join Date: Mar 2005
Posts: 1,547
bb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond reputebb99 has a reputation beyond repute

And remember to backup your data first - don't trust forum users not to break your data
bb99 is offline  
Old 03-07-2007, 04:10:31 PM     #7 (permalink)

 
Join Date: May 2007
Posts: 1,148
monaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond repute

Without seeing your code or schema it's diffucult to give specific advise, however I'd personally add a datetime field (saledate) to hold your date then do something like

select name, monthname(saledate), other_fields_you_want from item order by month(saledate)
__________________
Alex Monaghan - Drop Catch & Drop Lists - PM for details
Online Accounting|Pine Furniture|Barbie
monaghan is offline  
Old 03-07-2007, 04:11:46 PM     #8 (permalink)

 
Join Date: May 2007
Posts: 1,148
monaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond repute

Quote:
Originally Posted by bb99 View Post
And remember to backup your data first - don't trust forum users not to break your data
Don't trust anyone, not just forum users
monaghan is offline  
Old 04-07-2007, 03:52:17 PM     #9 (permalink)

 
Join Date: May 2007
Posts: 1,148
monaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond repute

Did you get it working to your liking?
monaghan is offline  
Old 04-07-2007, 06:05:16 PM     #10 (permalink)
Administrator
 
admin's Avatar
 
Join Date: Jun 2004
Posts: 8,601
admin has disabled reputation

Thumbs down

I managed to trash my data by changing the field type to date, it zapped all the field contents grrrrr I do have a backup but I need to do some data cleansing anyway, to make the categories more consistent.

I am still playing with it now.
admin is offline  
Closed Thread



Bookmarks

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 Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Domain Name Community Replies Last Post
Domain name. How to select the right domain names - 24-7PressRelease.com (press release) RSS Domain Name News 0 04-06-2007 10:59:12 AM
Domain name. How to select the right domain names - 24-7PressRelease.com (press release) RSS Domain Name News 0 31-05-2007 07:59:07 AM
How to select a domain name for your company - Honolulu Star-Bulletin RSS Domain Name News 0 26-03-2007 12:59:16 PM
bounce.co.uk - Public Statement from Nominet Beasty Domain Name Disputes 11 28-09-2006 02:28:30 PM
moving mysql from one server to another SecNam General Board 1 07-08-2005 12:29:32 PM


All times are GMT. The time now is 01:31:25 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0 RC 2
All content on Acorn Domains is member generated and is not moderated before posting. All content is viewed and used by you at your own risk and AD does not warrant the accuracy or reliability of any of the information. The views expressed are those of the individual contributors and not necessarily those of AD. Please contact us to report any issues or send a PM to "Admin".