Jump to content

Order sql results table by weigth [SOLVED]


Recommended Posts

Posted

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):

post-5667-0-00854000-1385902478_thumb.jpg


............ 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...

Posted

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.

Posted (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 by ARV187
Posted

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.

Posted

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.

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...