chester600 Posted August 27, 2006 Share Posted August 27, 2006 Hey all!I am quite new to php/MySQL and have hit a problem during learning them.I have created a table in my database that holds a user_id and the users age, which looks like this:[table][tr][td][b]user_id[/b][/td][td][b]age[/b][/td][/tr][tr][td]1[/td][td]56[/td][/tr][tr][td]2[/td][td]70[/td][/tr][tr][td]3[/td][td]17[/td][/tr][tr][td]4[/td][td]67[/td][/tr][tr][td]5[/td][td]72[/td][/tr][tr][td]6[/td][td]60[/td][/tr][tr][td]7[/td][td]99[/td][/tr][tr][td]8[/td][td]100[/td][/tr][tr][td]9[/td][td]98[/td][/tr][tr][td]10[/td][td]200[/td][/tr][/table]Now when I use this query in php:[code]$query = "SELECT user_id, age FROM members ORDER BY age DESC";[/code]I get the following output:[table][tr][td]user_id[/td][td]age[/td][/tr][tr][td]7[/td][td]99[/td][/tr][tr][td]9[/td][td]98[/td][/tr][tr][td]5[/td][td]72[/td][/tr][tr][td]3[/td][td]70[/td][/tr][tr][td]4[/td][td]67[/td][/tr][tr][td]6[/td][td]60[/td][/tr][tr][td]1[/td][td]56[/td][/tr][tr][td]10[/td][td]200[/td][/tr][tr][td]2[/td][td]17[/td][/tr][tr][td]8[/td][td]100[/td][/tr][/table]For some reason 200 is being treated as < 56 and 100 as < 17. Anyone have any ideas why this would be????Thanks in advance!Chester600 :) Link to comment https://forums.phpfreaks.com/topic/18838-order-by-help/ Share on other sites More sharing options...
redarrow Posted August 27, 2006 Share Posted August 27, 2006 Try this but yours should of worked.[code]$query = "SELECT user_id, age FROM members where age <= 200 ORDER BY age DESC";[/code] Link to comment https://forums.phpfreaks.com/topic/18838-order-by-help/#findComment-81305 Share on other sites More sharing options...
trq Posted August 27, 2006 Share Posted August 27, 2006 What field type is age? Link to comment https://forums.phpfreaks.com/topic/18838-order-by-help/#findComment-81307 Share on other sites More sharing options...
chester600 Posted August 27, 2006 Author Share Posted August 27, 2006 [quote author=thorpe link=topic=105859.msg423002#msg423002 date=1156717562]What filed type is age?[/quote]It is char.Thanks for your reply redarrow but that still gives the same output :( Link to comment https://forums.phpfreaks.com/topic/18838-order-by-help/#findComment-81309 Share on other sites More sharing options...
redarrow Posted August 27, 2006 Share Posted August 27, 2006 change char to int then try your statement. Link to comment https://forums.phpfreaks.com/topic/18838-order-by-help/#findComment-81311 Share on other sites More sharing options...
chester600 Posted August 27, 2006 Author Share Posted August 27, 2006 [quote author=redarrow link=topic=105859.msg423007#msg423007 date=1156717980]change char to int then try your statement.[/quote]Brilliant!!! Worked perfectly.....thanks ;D Link to comment https://forums.phpfreaks.com/topic/18838-order-by-help/#findComment-81322 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.