corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP SQL Help


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author PHP SQL Help
drax
Member

Registered: 5th Feb 05
Location: Sittingbourne, Kent
User status: Offline
13th Jul 07 at 12:33   View User's Profile U2U Member Reply With Quote

Hey guys,

Im pulling information out of a database, and one of the ways I need to do it is arranging by price, which is all well and good but the way its running the process is like this

1
24,600
4,000

If you can see what its doing, the way I need it to interpretate it is like this

1
4,000
24,600

Using decimal places, the field type is also a Varchar as it MAY need to have text in sometimes.
drax
Member

Registered: 5th Feb 05
Location: Sittingbourne, Kent
User status: Offline
13th Jul 07 at 12:36   View User's Profile U2U Member Reply With Quote

I have solved this already! Doh..

Using the ABS function

as shown here http://www.thewatchmakerproject.com/journal/231/comparing-numbers-in-mysql
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
13th Jul 07 at 15:22   View Garage View User's Profile U2U Member Reply With Quote

Looks to me like your data types are wrong - ie. you're storing as text not a number.

As text the order is correct - ie. 1,2,4 - rest of the 'word' doesn't affect the significance of the first value.

As a number, its length is important so they would order correctly.

You'll need to lose the commas though. Out of interest, past me the output from

SHOW FIELDS FROM tablename;
drax
Member

Registered: 5th Feb 05
Location: Sittingbourne, Kent
User status: Offline
13th Jul 07 at 16:31   View User's Profile U2U Member Reply With Quote

Im using a non interger type of field as there is possibility that the client needs to put a word or two in with the number,

Here are the fields

Field Type Null Key Default Extra
id int(11) NO PRI NULL auto_increment
adTitle varchar(30) YES NULL
Year varchar(4) YES NULL
Make varchar(30) YES NULL
Model varchar(30) YES NULL
Mileage varchar(8) YES NULL
Engine varchar(30) YES NULL
Colour varchar(30) YES NULL
Spec varchar(256) YES NULL
Overview varchar(256) YES NULL
Engine_Specs varchar(256) YES NULL
Electronics_Management varchar(256) YES NULL
Transmission varchar(256) YES NULL
Differential varchar(256) YES NULL
Suspension varchar(256) YES NULL
Interior_Saftey varchar(256) YES NULL
Exterior varchar(256) YES NULL
Condition varchar(256) YES NULL
Driving_Impression varchar(256) YES NULL
FOB varchar(30) YES NULL
UK_Landed varchar(30) YES NULL
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
13th Jul 07 at 17:26   View Garage View User's Profile U2U Member Reply With Quote

Is this the mileage field?

Might be better having an integer for miles and varchar for mileage_comment field or something?

That way you can do proper maths on the number - ie. order by / where .. between etc. and also format that comment field differently.

Don't forget also, if you allow text in with the number, your user might still break your ordering even with abs() function.

Also if the comma is left out you'll be in trouble.

2000
24,000
27000

... will order ...

24
2000
27000

You're also loosing the hundreds, tens and units of course.

OK unless you have cars with mileage all within 1000 of each other and you want an accurate order. Its not the end of the world but might look a bit shonky when its almost right but not actually accurate.
AndyKent
Member

Registered: 3rd Sep 05
User status: Offline
13th Jul 07 at 17:50   View User's Profile U2U Member Reply With Quote

I agree

Makes your life so much easier if you just choose int fields. I would always add a 'comment' field if I ever thought more information might be needed.....

Why might they need to add more info though? A mileage is fixed so what needs clarifying?
drax
Member

Registered: 5th Feb 05
Location: Sittingbourne, Kent
User status: Offline
13th Jul 07 at 18:07   View User's Profile U2U Member Reply With Quote

Its by price which is the ordering issue You guys are right, I may just change it to an Int, cheers.

Still learning php and SQL alot, only really kicked into it this last week

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
IS anyone good at .php programs ??? SteveW Geek Day 10 288
18th Mar 04 at 19:16
by AdiSRI
 
This is a pretty cool vx site and its free to join :D Rambo General Chat 17 865
25th Aug 06 at 20:09
by Sam
 
Unsure if anyone can help me with this Steve Geek Day 21 954
4th Oct 06 at 19:49
by Steve
 
SQL Server Bart Geek Day 1 837
1st Feb 07 at 16:44
by Samls
 
XML/PHP Laney Geek Day 6 799
26th Apr 07 at 15:03
by Ian
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP SQL Help 29 database queries in 0.0129220 seconds