Jump to content

Limiting amount of data pulled from an MySQL Database?


stublackett

Recommended Posts

Hi,

 

I've got a news system implemented which posts to index.php

But due to size constraints and usability rules I've decided against a scrollbar

 

So what I'd like to do is limit the amount of items pulled from a Database to 3 at a max, But those 3 being the latest 3 news items added to the database

 

Any ideas on how I can do this!?

 

Heres my code which pulls the news item(s) from the database, Obviously with screen sizes of my page it becomes an issue if there are more than 3 news items posted to the Database, So would like to limit the News posted to just 3, 3 items from the DB then being output onto the page

 

Any help is much appreciated!

 

CODE :

<?php #news-index.php By Stuart Blackett

include("dbconnect.php");

        $result = mysql_query("SELECT * FROM $db_table ORDER BY dtime DESC",$connect);

        //lets make a loop and get all news from the database

        while($myrow = mysql_fetch_assoc($result))

             {//begin of loop

               //now print the results:

               echo "<b>Title: ";

               echo $myrow['title'];

               echo "</b><br><br>Posted: ";

               echo $myrow['dtime'];
		   echo "<br> <br>";
               echo $myrow['text1'];
   			   echo "<br>";

               // Now print the options to (Read,Edit & Delete the news)

               echo "<br><a href=\"read_more.php?newsid=$myrow[newsid]\">Read Further</a>
			 ||  <a href=\"add_news.php\">Add News</a>
			   
                || <a href=\"edit_news.php?newsid=$myrow[newsid]\">Edit</a>

                 || <a href=\"delete_news.php?newsid=$myrow[newsid]\">Delete</a><br><br>";
			 				  
             }//end of loop

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.