alienmojo Posted February 8, 2007 Share Posted February 8, 2007 this is my first time to use the order by thing in php when i run the script it sayed that it failed here is the quiery im passing in SELECT * FROM estate WHERE price BETWEEN 0 AND 99999999999999 AND baths BETWEEN 0 AND 99999999999999 AND bedrooms BETWEEN 0 AND 99999999999999 AND ORDER BY price Quote Link to comment Share on other sites More sharing options...
hvle Posted February 8, 2007 Share Posted February 8, 2007 delete the AND before ORDER BY Quote Link to comment Share on other sites More sharing options...
alienmojo Posted February 8, 2007 Author Share Posted February 8, 2007 ok thanks that worked! it there a way to make it to where it it sorts by more that just the first number EX. its saying 9 > 80 Quote Link to comment Share on other sites More sharing options...
hvle Posted February 8, 2007 Share Posted February 8, 2007 use comma after order by: order by price, baths, beds Quote Link to comment Share on other sites More sharing options...
alienmojo Posted February 8, 2007 Author Share Posted February 8, 2007 no i only want it to sort by price but say for instance there is a price of 9 and a price of 80 its saying that the 9 is bigger the only thing i can thing of that can cause this maybe is the fact that they are being read in as strings instead of ints Quote Link to comment Share on other sites More sharing options...
hvle Posted February 8, 2007 Share Posted February 8, 2007 sorry, I misread again. when you're say ORDER BY price, mysql will sort from small to large (ascending) by default. So will get 9, then 80. if you like 80, and then 9, use ORDER BY price DESC Quote Link to comment Share on other sites More sharing options...
alienmojo Posted February 8, 2007 Author Share Posted February 8, 2007 sorry this is a little hard to put into words i will just show you the output PRICE 2 250000 250000 250000 7000000 80000 8000000 90000 basicly its just looking at the first digit from the left and sorting them that way Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 8, 2007 Share Posted February 8, 2007 Are they varchar instead of int? If so, you need to put the results in an array in PHP and then sort it after converting them to ints. Or fix the column to be an INT Quote Link to comment Share on other sites More sharing options...
hvle Posted February 8, 2007 Share Posted February 8, 2007 Ok, it look like you stored your price as string (Not recommended). However, here is a work around: ...ORDER BY cast(price as unsigned) Althought that can fix problem, it can cause other problem if you don't change the price to an appropriate data type. Quote Link to comment Share on other sites More sharing options...
alienmojo Posted February 8, 2007 Author Share Posted February 8, 2007 instead of casting it as unsigned can i put int or decimal Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 8, 2007 Share Posted February 8, 2007 change the column to a int in the database as your encounter more problams ok. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.