RE: [PHP-DB] ID numbers not sorting Properly
| From: | USA) | Date: | Fri, 12 Jul 2002 18:58:42 +0000 |
| Subject: | RE: [PHP-DB] ID numbers not sorting Properly | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-20519@lists.php.net to get a copy of this message | ||
I'm amazed at how many seasoned developers think that doing a select with no order by clause
will always return the records in the order they went into the database. That is an absolute no-no.
The problem is, it usually will, but try restoring a backup or bulk loading and see what happens.
Even if your database documentation (whatever it is) says it supports it, don't rely on it...
EVER! :-)
Users are worse, USER: "I want my report in the order that the entries went in" ..
DEVELOPER: "sorry, for 3 years now you've been storing data but no entry date and your
keys are not incremental, not to mention your program reuses keys" ... USER: "well fix
it" ... DEVELOPER: "well, I can't fix it, not for the old data anyway" ...
USER: "Well, that's just great! I thought you were suppose to be able to help us!"
... DEVELOPER: "You picked the tool, we just do our best to support it." ...
Anyway... sorry for the tangent. :-)
<>< Ryan
-----Original Message-----
From: Martin Clifford [mailto:MLC1@nrc.gov]
Sent: Friday, July 12, 2002 12:14 PM
To: Richard.Hutchins@GetingeCastle.com; php-db@lists.php.net;
dinsmoreb@surfbest.net
Subject: RE: [PHP-DB] ID numbers not sorting Properly
MySQL has no obligations when it comes to sorting result sets. If you want it sorted a certain way,
it'd be in your best interest to declare it with ORDER BY item_id ASC, if that's your
flavor.
Martin Clifford
Homepage: http://www.completesource.net
Developer's Forums: http://www.completesource.net/forums/
>>> "Hutchins, Richard" <Richard.Hutchins@GetingeCastle.com> 07/12/02
>>> 01:44PM >>>
Would using sort($result); solve the problem? I believe the default sort
order is ascending. Try using sort($result) before your while($myrow =
mysql_fetch_array($result)) statement and see if that fixes things.
I also noticed that you don't use an ORDER BY clause in your sql statement,
but if the query works in MySQL, then I guess it's not necessary?
Good Luck
Rich
-----Original Message-----
From: Blaine D. Dinsmore [mailto:dinsmoreb@surfbest.net]
Sent: Friday, July 12, 2002 12:34 PM
To: php-db@lists.php.net
Subject: [PHP-DB] ID numbers not sorting Properly
I'm using MySQL and I have noticed that my primary key which are
autoincrementing numbers do not sort properly when pulling the results to
the browser. They are showing consecutively all the way until 150 then they
start going backwards for example:
157
156
155
154
159
160
161
162
163
When I do a query in MySQL they are sequenced correctly but using the php
mysql_fetch_array() I get this crazy numbering sequence. Does anyone know
what this could be?
Here is my code:
<body bgcolor="#000000" text="#FFFFFF" link="#99FF33"
vlink="#FFFF00"
alink="#99CCFF">
<FONT FACE=ARIAL>
<?php
include('functions.php');
$dbase="lims_issues";
If ($_GET[order] == 1) {
$sql= "SELECT probid,resolved,loggerid,DATE_FORMAT(logdate,'%m-%d-%Y') AS
date,priority,screen,descript,notes" .
" FROM bugs";
}
If ($_GET[order] == 2) {
$sql= "SELECT probid,resolved,loggerid,DATE_FORMAT(logdate,'%m-%d-%Y') AS
date,priority,screen,descript,notes" .
" FROM bugs WHERE resolved=0";
}
If ($_GET[order] == 3) {
$sql= "SELECT probid,resolved,loggerid,DATE_FORMAT(logdate,'%m-%d-%Y') AS
date,priority,screen,descript,notes" .
" FROM bugs WHERE resolved=1";
}
If ($_GET[order] == 4) {
$sql= "SELECT probid,resolved,loggerid,DATE_FORMAT(logdate,'%m-%d-%Y') AS
date,priority,screen,descript,notes" .
" FROM bugs WHERE discussed=0";
echo("<font size=5><b>Issues Not Disscussed With
Beckman</b></font>");
}
If ($_GET[order] == 5) {
$sql= "SELECT probid,resolved,loggerid,DATE_FORMAT(logdate,'%m-%d-%Y') AS
date,priority,screen,descript,notes" .
" FROM bugs WHERE discussed=1";
echo("<font size=5><b>Issues Disscussed With Beckman</b></font>");
}
mysqlconn($dbase,$sql);
while( $myrow = mysql_fetch_array($result) ){
?>
<Table border="1" cellpadding="0" cellspacing="0"
style="border-collapse:
collapse" bordercolor="#777777" width="100%">
<TR bgcolor="#006600">
<TD colspan=3>
<?php echo("<b>Issue ID: </b>" . "<a
href=modify.php?getprobid="
.$myrow["probid"] .">" . $myrow["probid"] .
"</a>"); ?>
</TD>
<?php
if ($myrow["resolved"] == '1') {
Echo("<TD bgcolor=#006600>");
Echo("<b><font color=#FFFFFF>Resolved</font></b>");
Echo("</TD>");
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php