Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

limiting amount of rows displayed from database

Status
Not open for further replies.

d3sol4t3

Programmer
Oct 27, 2005
40
GB
Hi, how would i limit the amount of rows displayed from database?

Example


look in the big green table in the middle of the page, the one where i have 10 rows saying 'How many rows'.

Say if i wanted to limit the amount displayed to 8, what code would i iimplement to do this.

Here is the current code being used for main.php:



**OPTIONAL**

Once 8 rows have been inserted, then the user click 'more...' which takes them to a page displaying all the news from that category from the past week.

For example:

 
to limit the number of rows to 8 add the words LIMIT 8 to the end of your sql query.
 
and to do the second bit, have the more button add a queryvar to the end of the url

Code:
<a href="<?=$_SERVER['PHP_SELF']?>"?limit=none">more...</a>

and in your code test the value
Code:
if (isset($_GET['limit'])):
  $limit = $_GET['limit'] == "none" 
           ? "" 
           : "Limit ".$_GET['limit'];
endif;
$tablename = "";//name of table
$where = "" ; //where clause
$sql = "Select * from $tablename $where $limit";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top