AdRock Posted August 6, 2008 Share Posted August 6, 2008 Is this possible and how? I want to get the last 5 records out of a table order desc and I want the last record entered to display the title, date and content so it's like the intro. The other 4 records I would like just the title to be displayed. $sql="SELECT title, content, DATE_FORMAT(time, '%D %M %Y') as date, alternate FROM news WHERE archived='n' ORDER BY date desc LIMIT 1"; // Perform a query getting back a MySQLResult object $result = $db->query($sql); // Iterate through the results while ($row = $result->fetch()) { echo ( '<h4 class="news-heading"><a href="http://www.jackgodfrey.org.uk/news/latest-news/1">'.$row['title'].'</a></h4><p style="text-align:left; font-size: 10px;margin-top:0 !important;">Date added: '.$row['date'].'</p>' ); echo ('<p>'.nl2br(ShortenText(str_replace('&','&',$row['content']))).'<a href="http://www.jackgodfrey.org.uk/news/latest-news/1">Read More</a></p>'); } This is what i have at the moment which displays only the first record. What i tried is have another query which gets all ther records and have another while loop underneath the first while loop which only displays the titles but it's outputting the title of the already displayed article. IS there a way of getting 5 records before the last record inserted? Link to comment https://forums.phpfreaks.com/topic/118404-how-to-display-all-fields-in-tforst-row-and-only-selected-fields-after/ Share on other sites More sharing options...
MasterACE14 Posted August 6, 2008 Share Posted August 6, 2008 here's how you grab only the 5.... $sql="SELECT title, content, DATE_FORMAT(time, '%D %M %Y') as date, alternate FROM news WHERE archived='n' ORDER BY date desc LIMIT 5"; not sure about the other one. Link to comment https://forums.phpfreaks.com/topic/118404-how-to-display-all-fields-in-tforst-row-and-only-selected-fields-after/#findComment-609403 Share on other sites More sharing options...
PFMaBiSmAd Posted August 6, 2008 Share Posted August 6, 2008 Simple if/else logic - <?php // execute query here $first_line = TRUE; // initialize a flag before your loop // Iterate through the results while ($row = $result->fetch()) { if($first_line) { // this is the first line, do any special processing needed for the first line here $first_line = FALSE; // set the flag false } else { // this is not the first line, do normal processing here } } ?> Link to comment https://forums.phpfreaks.com/topic/118404-how-to-display-all-fields-in-tforst-row-and-only-selected-fields-after/#findComment-609841 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.