How to list by highest date in PHP
<p>Hey guys so I am having some trouble using the following:</p>

<pre><code>for ($i = 0; $i &lt; count($noncompUsername); $i++)
{
    $tsql ="SELECT firstname,lastname,email,phone,statuschangedate FROM csvdata WHERE username = :username ORDER BY statuschangedate";
    $tgetmeminfo=$DBH-&gt;prepare($tsql);
    $tgetmeminfo-&gt;execute(array(':username' =&gt; $noncompUsername[$i]));
    while ($trow = $tgetmeminfo-&gt;fetch(PDO::FETCH_ASSOC)){

        $csvFirst = $trow['firstname'];
        $csvLast = $trow['lastname'];
        $csvEmail = $trow['email'];
        $csvPhone = $trow['phone'];
        $csvDate = $trow['statuschangedate'];
        $timediff = strtotime($date) - strtotime($csvDate);
        $timediff = floor($timediff/86400);

        $sql ="SELECT MailingAdrs FROM insuranceverificationdisclaimer WHERE TraineeUsername = :tusername";
        $getmeminfo=$DBH-&gt;prepare($sql);
        $getmeminfo-&gt;execute(array(':tusername' =&gt; $noncompUsername[$i]));
        while ($row = $getmeminfo-&gt;fetch(PDO::FETCH_ASSOC)){

            $csvAddrs = $row['MailingAdrs'];
            $change = 1;
        }
        if($change != 1)
        {
            $csvAddrs = "No address";
        }
        $change = 0;
        echo "$timediff, $csvFirst $csvLast, $csvEmail, $csvPhone, $csvAddrs";
    }
    echo "
    &lt;br&gt;
    ";
}
</code></pre>

<p>Now this works but the part I want to point out is the <code>$tsql ="SELECT firstname,lastname,email,phone,statuschangedate FROM csvdata WHERE username = :username ORDER BY statuschangedate";</code> - now when I do this and get the integer of the statuschangedate to the current date and print it out as an integer, it is not ordered properly based on the date.</p>

<p>So I need to get this to order by the oldest date on top and as follows...</p>

<p>Thank you!</p>

<p>David</p>
