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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.