从Mysql表转换时,日期失去位置

My problem is that when I display my SQL table, the date is in a different order as it is on the SQL table, so the date does not correspond with the eid.

The SQL table has the following order.

EID 72: DATE: 2014-04-08 SUBJECT: 3rd event

EID 70: DATE: 2014-04-02 SUBJECT: 1st one

EID 69: DATE: 2014-04-01 SUBJECT: 2nd Event

EID 71: DATE: 2014-03-31 SUBJECT: Fourth event

However it displays in html as

EID: 71 DATE: 2014-04-08 SUBJECT: 3rd event

EID: 72 DATE: 2014-04-01 SUBJECT: Fourth event

EID: 69 DATE: 2014-04-02 SUBJECT: 1st one

EID: 70 DATE: 2014-03-31 SUBJECT: 2nd Event

For some reason when translating from SQL through PHP, the date loses it's order. Here is my php code which displays the results

$conn = mysql_connect("localhost","admin","password") or die ("could not connect to the server");
        mysql_select_db("app") or die ("that database could not be found");

        $result = mysql_query("SELECT * FROM  `notification` WHERE `date` AND `active`=0 < NOW()") or die ("The query could not be completed. Please try again later");

        while($noticerow=mysql_fetch_array($result, MYSQL_ASSOC))
        {
            $nid[] = $noticerow['nid'];
            $eid[] = $noticerow['eid'];
            $subject[] = $noticerow['subject'];
            $noticedate[] = $noticerow['date'];
        }

        $a=0;
        while(mysql_num_rows($result)>$a)
        {
            echo "<tr><td><a onclick='location.href=\"calendar.php?action=display_event&oid=".$eid[$a]."\"'>".$eid[$a]."</a></td><td><a onclick='location.href=\"calendar.php?action=display_event&oid=".$eid[$a]."\"'>".$noticedate[$a]."</a></td><td><a onclick='location.href=\"calendar.php?action=display_event&oid=".$eid[$a]."\"'>".$subject[$a]."</a></td><td><form action='rnotice.php' method='POST'><button value='submit' class='btn btn-danger pull-right' type='submit' onclick='location.href=\"calendar.php?action=display_event&oid=".$eid[$a]."\"'>Remove</button><input name='eid' type='hidden' value=".$eid[$a]."></form></td></tr>";
        $a++;
        }

you need to use the order by keyword in the SQL statement but I don't know the columns name you are using.

Assuming that you want to order them by EID and you have a column name called EID for that your select statement should be something like:

SELECT * FROM  `notification` WHERE `date` AND `active`=0 < NOW() order by eid ASC

if you want to sort it by date then

SELECT * FROM  `notification` WHERE `date` AND `active`=0 < NOW() order by `date` ASC

To sort the records in a descending order, you can use the DESC keyword instead of ASC