trouble displaying mysqli database results in correct order
<p>I have a table in my database which stores events and the date they expire. What i want to do is display all the events on my website but display the current events first then the expired events after?</p>

<p>i have tried the following sql</p>

<pre><code>$sql = "SELECT noticeID, notice, noticeDesc, noticeIMG, noticeDate,
expiryDate FROM tbl_notices GROUP BY noticeID ,expired ORDER BY
expiryDate ASC";
</code></pre>

<p>but that returns the expired results first due to the expiryDate being ordered ASC in my query.</p>

<p>My tbl_notice structure looks like this</p>

<pre><code>noticeID =&gt; int(4)
notice =&gt; VARCHAR(100)
noticeDesc =&gt; text
noticeDate =&gt; timestamp
noticeIMG =&gt; VARCHAR(40)
expiryDate =&gt; datetime
expired =&gt; int(1) 0 for current or 1 for expired
</code></pre>

<p>my php code is</p>

<pre><code>$sql = "SELECT noticeID, notice, noticeDesc, noticeIMG, noticeDate,
expiryDate FROM tbl_notices GROUP BY noticeID ,expired ORDER BY expiryDate ASC";
$result = mysqli_query($conn,$sql);

        if ($result-&gt;num_rows &gt; 0)
        {
            // output data of each row
            while($row = $result-&gt;fetch_assoc())
            {
                $id = $row['noticeID'];
                $title = htmlspecialchars($row['notice']);
                $urltitle = strtolower($title);
                $urltitle = str_replace(" ","-",$urltitle);
                $date = $row['noticeDate'];
                $datetime1 = new DateTime("2010-06-20");
                $expiryDate = $row['expiryDate'];
                $link = "announcements.php";
                $body = strip_tags($row['noticeDesc']);
                $filename = $row['noticeIMG'];
                if($filename != "")
                {
                    $imgLink = "images/".$filename;
                }
                else
                {
                    $imgLink = "images/announcement-default.jpg";
                }?&gt;

                &lt;div class="news-container-sm"&gt;
                    &lt;img class="pin" src="images/thumbtack_pushpin_2_thumb.png" alt="News Pin" title="News Pin"&gt;
                    &lt;div class="news-img"&gt;&lt;img class="fluid" src="&lt;?php echo $imgLink?&gt;" alt="&lt;?php echo $title?&gt;" title="&lt;?php echo $title?&gt;" /&gt;&lt;/div&gt;
                        &lt;div class="fluid news-headline"&gt;&lt;?php echo $title?&gt;
                            &lt;span class="fluid news-date"&gt;&lt;?php echo "expires in ".humanTiming( strtotime($expiryDate) );?&gt;&lt;/span&gt;
                        &lt;/div&gt;
                    &lt;div class="fluid news-desc"&gt;&lt;?php echo $body;?&gt;&lt;/div&gt;
                &lt;/div&gt;&lt;?php
            }           
        }
        else
        {
            echo "No Announcements!";
        }
        $conn-&gt;close();?&gt;
</code></pre>

<p>but like i say that is returning the expired records first because the expiryDate which being sorted Ascending would be first, how would i push the expired records to the end?</p>

<p>so effectively sort and display all the current notices then sort and display the expired notices.</p>

<p>hope this makes sense
any help is appreciated</p>

<p>Many Thanks
Luke</p>