ARV187 Posted December 1, 2013 Report Share Posted December 1, 2013 Hi all, Im trying make a aircraft table, the only part that fault me is order by weight. The data not is been order correctly (see image): ............ FROM phpvms_aircraft ORDER BY phpvms_aircraft.weight"; Seems that fail is in order number by number and not full cuantity. Ex, order by weight ASC: 12005324 (the fourth digit is smaller than 3) 1203 (the fourth digit is bigger than 0) The heavier aircraft is ordained as the lightest How i can resolve this? Thanks, regards... Quote Link to comment Share on other sites More sharing options...
freshJet Posted December 1, 2013 Report Share Posted December 1, 2013 This shouldn't be in Skinning, nonetheless: FROM phpvms_aircraft ORDER BY weight ASC Quote Link to comment Share on other sites More sharing options...
ARV187 Posted December 1, 2013 Author Report Share Posted December 1, 2013 Hi itrobb, then to a homemade table what is the correct place in forum? About my question, yes, that is my code, but not work because compare digit by digit, not the full number. Only i find one solution, set all weight aircraft with same digit numbers. But is a long work. Quote Link to comment Share on other sites More sharing options...
freshJet Posted December 1, 2013 Report Share Posted December 1, 2013 Should go in Support or Code Snippets. Anyway, I was not asking a question, that should be the correct code to use. Quote Link to comment Share on other sites More sharing options...
ARV187 Posted December 1, 2013 Author Report Share Posted December 1, 2013 Thanks, a moderator must move topic then. Quote Link to comment Share on other sites More sharing options...
freshJet Posted December 1, 2013 Report Share Posted December 1, 2013 Did you try the code though? Quote Link to comment Share on other sites More sharing options...
ARV187 Posted December 1, 2013 Author Report Share Posted December 1, 2013 Yes, with ASC included. The problem is how sql orders the data, digit to digit, from left to right, not the full cuantity. Quote Link to comment Share on other sites More sharing options...
freshJet Posted December 1, 2013 Report Share Posted December 1, 2013 I don't know what you mean, what do you mean by digit to digit? These are integers and therefore there is no reason why they shouldn't sort. Did you try DESC? Quote Link to comment Share on other sites More sharing options...
ARV187 Posted December 1, 2013 Author Report Share Posted December 1, 2013 (edited) See the attached image in first post, in mysql is sorted wrong, because makes a comparison number by number, not by the total amount.For example, with tu154 & extra300, the heavy aircraft is tu154, but he compare digit by digit: 122000 1342 1 & 1 (same number), 2 & 3 (three is greater than two) then sql sort the extra-300 (1342lbs) in second place because in their opinion is greater. Only work if i put the same number of digits, For example six digits: Tu-154 (122000) and extra-300 (001342) Edited December 1, 2013 by ARV187 Quote Link to comment Share on other sites More sharing options...
freshJet Posted December 1, 2013 Report Share Posted December 1, 2013 Check the field type, make sure it's INT Quote Link to comment Share on other sites More sharing options...
ARV187 Posted December 1, 2013 Author Report Share Posted December 1, 2013 Hi itrobb weight is how: weight varchar(15) by default in aircraft table I dont know how change it, and if is dangerous make a change in DB. Anyway I changed all airplanes weigth to six digits and work. Thanks. Quote Link to comment Share on other sites More sharing options...
freshJet Posted December 1, 2013 Report Share Posted December 1, 2013 If it's working that's fine. VARCHAR means a mix of different characters, it should be integer, INT. And no, it's not dangerous. You can do it through the Structure tab at the top in phpMyAdmin. 1 Quote Link to comment Share on other sites More sharing options...
ARV187 Posted December 1, 2013 Author Report Share Posted December 1, 2013 Ok, was easy, im a ignorant jeje. Never get up without learn anything new. All extra ceros was erased, and data sorted correctly. Thanks! 1 Quote Link to comment Share on other sites More sharing options...
ARV187 Posted December 1, 2013 Author Report Share Posted December 1, 2013 Can I change the type to "imagelink" & "downloadlink" from text to varchar? I read that varchar is best to show much url in same table Quote Link to comment Share on other sites More sharing options...
freshJet Posted December 1, 2013 Report Share Posted December 1, 2013 I suppose, but TEXT would be more efficient. 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.