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 :)

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

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";

You must Print out or Echo $pagination. Something like

echo $pagination;

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

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>";

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.