Pagination script link question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
abbey4biz
Forum Commoner
Posts: 32
Joined: Wed Nov 23, 2011 12:25 pm

Pagination script link question

Post by abbey4biz »

Please am having problem with this pagination scripts. I needed to link to the next page and I don't know if the url is correct, please kindly help me check through.

Check the codes below:

Code: Select all

function products(){

require_once ('dbc1.php');

// Number of records to show per page:

$display = 10;

// Determine how many pages there are...

if (isset($_GET['p']) && is_numeric($_GET ['p'])) { // Already been determined.

$pages = $_GET['p'];

} else { // Need to determine.

// Count the number of records:

if (isset($_GET['product'])){

$prod = ($_GET['product']);
}

?>

<title><?php echo $prod;  ?> | The MarketPlace</title>

<?php

$q = "SELECT COUNT(id) FROM products WHERE category = '$prod' ";
$r = @mysqli_query ($dbc, $q);
$row = @mysqli_fetch_array ($r, MYSQLI_NUM);

$records = $row[0];

// Calculate the number of pages...


if ($records > $display) { // More than 1 page.

$pages = ceil ($records/$display);

 } else {

$pages = 1;

}

} // End of p IF.

// Determine where in the database to start returning results...

if (isset($_GET['s']) && is_numeric ($_GET['s'])) {

	$start = $_GET['s'];

} else {

	$start = 0;

}

// Make the query:


	$q = "SELECT * FROM products WHERE category = '$prod' LIMIT $start, $display ";

$r = @mysqli_query ($dbc, $q);

 if ($r){

	echo '<div align="center"><table cellspacing="2" cellpadding="5" 
width="100%"   style="border:solid; border-width:1px; " bgcolor="#CCCCCC"><tr align="center"><td><b>Product</b></td><td> <b>Description</b> </td><td><b>Phone No</b></td><td><b>Price</b></td></tr>
		';
		
		$bg = '#eeeeee'; // Set the initial background color.

		
		while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
		
		$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color.
		$imgurl = 'uploads/'.$row["image"].'';
		
				
		echo '<tr bgcolor="' . $bg . '" align="center"><td><b>'.$row['prodname'].'</b><br>';
		
		echo '<a href="display.php?id='.$row['id'].'&prod='.$row['category'].'"><img src= '.$imgurl.' width=100 height=80 border=0><br> <font size="-2">Click for more details...</font></a></td>' ;
		
		 echo '<td width="150" align="left" >' . $row['proddescr2'] . '</td><td align="left">Call Vendor on:<br>'. $row['phone'] . '</td><td align="left">N' . number_format($row['price'],2) . '</td></tr>';
		
		
	}
	
	echo '</table></div>';

}else
echo "No products found!";
	

if ($pages > 1) {

// Add some spacing and start a paragraph:
 echo '<br /><p>';
	// Determine what page the script is on:
	
		$current_page = ($start/$display) + 1;
		
		// If it's not the first page, make a Previous button:
		
if ($current_page != 1) {
	
echo '<a href="m_category.php?product=home&s=' . ($start - $display) . '&p=' . $pages . '">Previous</a> ';
}

// Make all the numbered pages:
	for ($i = 1; $i <= $pages; $i++) {
	
	if ($i != $current_page) {
		echo '<a href="m_category.php?product=home&s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> ';
		
	} else {
	
	echo $i . ' ';
	}
	
} // End of FOR loop.


// If it's not the last page, make a Next button:

if ($current_page != $pages) {
	
echo '<a href="m_category.php?product=home&s=' . ($start + $display) . '&p=' . $pages . '">Next</a>';

}
echo '</p>'; // Close the paragraph.

} // End of links section.
 
 
}
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Pagination script link question

Post by social_experiment »

viewtopic.php?f=1&t=135757
Is this question related to the url above?
abbey4biz wrote:I don't know if the url is correct
what happens when you click on the link to go to the next page
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply