pznmynd Posted January 12, 2009 Share Posted January 12, 2009 Greetings, I have a news column on a site were i pull the news from a database, Currently I am using a loop to get all the news and display it, for a loop im using a while, What are my options to display only the top 15 news posts (in Descending order), Take a look at my snippet and see if you can help, Thanks in advance, <?php // load the configuration file. include("config.php"); //load all news from the database and then OREDER them by newsid $result = mysql_query("SELECT * FROM news ORDER BY newsid DESC",$connect); //lets make a loop and get all news from the database while($myrow = mysql_fetch_array($result)) {//begin of loop //now print the results: echo "<b> "; echo "<br><a href=\"read_more.php?newsid=$myrow[newsid]\">"; echo $myrow['title']; echo "</a></b>"; echo "<br><hr>"; echo "<i>"; echo $myrow['dtime']; echo "</i><hr align=left width=160>"; echo $myrow['text1']; echo "</hr> "; }//end of loop ?> /scott Link to comment https://forums.phpfreaks.com/topic/140509-solved-php-msq-assistance/ Share on other sites More sharing options...
ngreenwood6 Posted January 12, 2009 Share Posted January 12, 2009 I would look into pagination. Link to comment https://forums.phpfreaks.com/topic/140509-solved-php-msq-assistance/#findComment-735262 Share on other sites More sharing options...
pznmynd Posted January 12, 2009 Author Share Posted January 12, 2009 I would look into pagination. Sooo you suggest i use ID numbers for the news entries in the data base and call them taht way... ?? (my understanding of pagination), Surly there is a simpler way.. thanks for you help sounds like it could work. Link to comment https://forums.phpfreaks.com/topic/140509-solved-php-msq-assistance/#findComment-735265 Share on other sites More sharing options...
ngreenwood6 Posted January 12, 2009 Share Posted January 12, 2009 You can add a limit clause to your query but then you are only ever going to get that many results. With pagination you can have 100 results and limit it to 10 per page with 10 pages. Limit clause example; $result = mysql_query("SELECT * FROM news ORDER BY newsid DESC LIMIT 15",$connect); Link to comment https://forums.phpfreaks.com/topic/140509-solved-php-msq-assistance/#findComment-735266 Share on other sites More sharing options...
pznmynd Posted January 12, 2009 Author Share Posted January 12, 2009 Thanks mate thats what i was looking for. Link to comment https://forums.phpfreaks.com/topic/140509-solved-php-msq-assistance/#findComment-735281 Share on other sites More sharing options...
ngreenwood6 Posted January 12, 2009 Share Posted January 12, 2009 You might want to look into the LIMIT clause of mysql because you can also set it up so that if the user wants to view the next 15, you could change the query to something like this: $result = mysql_query("SELECT * FROM news ORDER BY newsid DESC LIMIT 16, 30",$connect); Link to comment https://forums.phpfreaks.com/topic/140509-solved-php-msq-assistance/#findComment-735283 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.