0

Hi,

I had developed a viewing table from mysql database using php and it is showing me the whole list of contents in a single webpage. I would like to know if there anyway i can actually split the contents into multiple pages for easy viewing??

Your help is greatly appreciated.

Cheers :)

4
Contributors
7
Replies
16
Views
7 Years
Discussion Span
Last Post by futhonguy
0

Hi,

I had developed a viewing table from mysql database using php and it is showing me the whole list of contents in a single webpage. I would like to know if there anyway i can actually split the contents into multiple pages for easy viewing??

Your help is greatly appreciated.

Cheers :)

Basically what u r supposed to do is restrict ur query from fetching all the records at once through LIMIT clause...
The technique is called pagination... u can find loads of threads in the forum and on google...
Hope this helps...

Edited by venkat0904: n/a

0

Hi, i managed to find some examples on the google and work my way with my examples and queries that other had posted on forums. I managed to sort out and limit my total rows of data to 10 per page. However i could not see the 'next' or 'prev' link shown. can anyone help me to find out where is the mistake i made?
Cheers

$val_d = $_POST['devicesearch'];

/* Set current, prev and next page */ 
$page = (!isset($_GET['page']))? 1 : $_GET['page'];  
$prev = ($page - 1); 
$next = ($page + 1); 

/* Max results per page */ 
$max_results = 10; 

/* Calculate the offset */ 
$from = (($page * $max_results) - $max_results); 

/* Query the db for total results. You need to edit the sql to fit your needs */ 
$sql = "SELECT device_id FROM device";
$result = mysql_query($sql) or die (mysql_error()); 

$total_results = mysql_num_rows($result); 

$total_pages = ceil($total_results / $max_results); 

$pagination = ''; 

if(isset($_POST['Device Search'])){ 
$search = '&$val_d=' . $val_d; 
} else { 
$search = ''; 
} 

/* Create a PREV link if there is one */ 
if($page > 1) 
{ 
$pagination .= '<a href="FTsearchprocessDEV_113009.php?page='.$prev.$search.'">Previous</a> '; 
} 

/* Loop through the total pages */ 
for($row = 1; $row <= $total_pages; $row++) 
{ 
if(($page) == $row) 
{ 
$pagination .= $row; 
} 
else 
{ 
$pagination .= '<a href="FTsearchprocessDEV_113009.php?page='.$row.$search.'">$row</a>'; 
} 
} 

/* Print NEXT link if there is one */ 
if($page < $total_pages) 
{ 
$pagination .= '<a href="FTsearchprocessDEV_113009.php?page='.$next.$search.'">Next</a>'; 
} 

/* Now we have our pagination links in a variable($pagination) ready to print to the page. 
I put it in a variable because you may want to show them at the top and bottom of the page */ 

/* Below is how you query the db for ONLY the results for the current page */ 
$result= mysql_query("select * 
		from device 
		WHERE device_num LIKE '%$val_d%' or '%$val_d'
		LIMIT $from, $max_results "); 

//this is where I print my current results to the page
include "FTsearchtable113009.php";
0

Thanks codewalkz,

However the display showed "$row$row$row..." instead of the page number. Any idea why as i still cant figure out where is the program too.
Cheers

0

replace your single quotes with double quotes, and your double quotes inside the string with single quotes.PHP interpret variables inside a string with double-quotes on them.

Example:

$pagination .= "<a href='FTsearchprocessDEV_113009.php?page='".$row.$search."'>$row</a>";
0

HI, i can only pass the search query to page 1 of the displaying results, however the 2nd page of the results are not working.. any idea why?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.