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
https://forums.phpfreaks.com/topic/285733-query-not-sorting-in-asc-order/
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'

Archived

This topic is now archived and is closed to further replies.

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