Jump to content

query not sorting in ASC order?


searls03

Recommended Posts

my php query:

 <?php  $sql1 = mysql_query("SELECT * FROM attendance ORDER BY id ASC");
while($row1 = mysql_fetch_array($sql1)){
$current = $row1["id"];
$name = $row1["name"];
echo $current;
echo "<br>";
}

is not sorting properly.  it is putting all 6 digit numbers before 5 digit numbers....here is what it is returning

 

100000

...

311655
311657
311711
311789
311790
311791
311792
311793
311794
311795
69326
69390
69451
69547
99985
99989
99990
99991
99992
99993
99995
99996
99997
99998
99999

 

does it have anything to do with the numbers not being consecutive?  I can't have this.......I have another insert query that adds one to the last number output....which clearly it won't do because the new would be the same as the first number.  can anyone help me with this?

Link to comment
Share on other sites

Nope, it is sorting in alphanumeric order. A '3' comes before '6'. This tells me that you have the 'id' field set as a varchar or some other non-numeric (i.e. text) type. Your ID field should be changed to an INT (integer) type so that it knows to sort in numeric order.

 

What does the following query return

 

SELECT DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'attendance'
  AND COLUMN_NAME = 'id'
Edited by Psycho
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.