Jump to content

Recommended Posts

someone guide me on adding page limit please

 

here is my sql

 

function getDetails($ID) {
		$posts = array();
		$sql    = "SELECT * FROM `tbl` AS d
            WHERE d.id = '".$ID."'";
		$rs = executeSql($sql);
		while($row = mysql_fetch_array($rs)) {
		$posts[] = $row;
		}
		return $posts;	
    }	

 

and this is how i display it

 

<?php

if(!count($adsPost)){
print 'no records';
}else{

foreach($adsPost as $p){
echo "<a href=\"ads_details.php?Category=$catName&ID=".$p['id']."\">".$p['adtitle']."</a>, ".$p['postersname'].", ".date('F jS, Y, g:i a',$p['adtime'])."<br/>";
}
}

?>	

 

i wish to add 15 results in a page, anyone know how to get it done?

 

i want it like

 

<< first page 1 2 3 4 5 [6] 7 last page>>

Link to comment
https://forums.phpfreaks.com/topic/243836-help-add-pagination/
Share on other sites

OP, instead of all the helpful advice you have been given, i'll attempt to explain pagination. Pagination works based on the offset, this is what actually makes it possible.

 

Heres an explanation of whats going on

 

1. Grab current page number in the HTTP VAR

$currentpage = $_GET['page']

2. Count the number of rows inside the table you are going to display in the screen

$num_rows = mysql_num_rows($query);

3. Create a variable, name it what you want in order to set a limit for the results per page ($rowsperpage= 10)

4. Calculate the total number of pages you are to get, you will need this...

 

$totalpages= ceil($num_rows/$rowsperpage)

 

5. Now we now how the total number of pages, and the number of results per page to display

6. We need to create an offset, meaning display a certain number of results from starting from this offset based on the current page number

 

$offset = ($currentpage - 1) * $rowsperpage;

 

7. Now plug this offset into your second query which will actually DISPLAY your content based on the offset, and the total page. The offset tells the code where to start in the query and the total pages tells it where to stop.

 

$sql = mysql_query("SELECT * FROM table_name LIMIT $offset, $rowsperpage");

 

8. Create a while loop, display the data.

 

http://www.phpfreaks.com/tutorial/basic-pagination

Link to comment
https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1252374
Share on other sites

i don't help people that just want the cde written for them, if you want to learn PHP, study and view the provided links..they explain how it works..im not going to write something here that has already been written and explained somewhere else

Link to comment
https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1252476
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.