php - trouble displaying mysqli database results in correct order -


i have table in database stores events , date expire. want display events on website display current events first expired events after?

i have tried following sql

$sql = "select noticeid, notice, noticedesc, noticeimg, noticedate, expirydate tbl_notices group noticeid ,expired order expirydate asc"; 

but returns expired results first due expirydate being ordered asc in query.

my tbl_notice structure looks this

noticeid => int(4) notice => varchar(100) noticedesc => text noticedate => timestamp noticeimg => varchar(40) expirydate => datetime expired => int(1) 0 current or 1 expired 

my php code is

$sql = "select noticeid, notice, noticedesc, noticeimg, noticedate, expirydate tbl_notices group noticeid ,expired order expirydate asc"; $result = mysqli_query($conn,$sql);          if ($result->num_rows > 0)         {             // output data of each row             while($row = $result->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";                 }?>                  <div class="news-container-sm">                     <img class="pin" src="images/thumbtack_pushpin_2_thumb.png" alt="news pin" title="news pin">                     <div class="news-img"><img class="fluid" src="<?php echo $imglink?>" alt="<?php echo $title?>" title="<?php echo $title?>" /></div>                         <div class="fluid news-headline"><?php echo $title?>                             <span class="fluid news-date"><?php echo "expires in ".humantiming( strtotime($expirydate) );?></span>                         </div>                     <div class="fluid news-desc"><?php echo $body;?></div>                 </div><?php             }                    }         else         {             echo "no announcements!";         }         $conn->close();?> 

but returning expired records first because expirydate being sorted ascending first, how push expired records end?

so sort , display current notices sort , display expired notices.

hope makes sense appreciated

many luke

use form of query:

$sql = "select noticeid, notice, noticedesc, noticeimg, noticedate, expirydate tbl_notices order expired, expirydate asc"; 

group in original query excessive.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -