Pagination and Switch problem

I am a beginner at PHP. I’m trying to learn pagination. I was able to get the pagination on this page to work - even though it’s ugly and shows all the available pages.

Problem is the main area of that “website”, where the Customer Records list shows up, uses a switch statement to display info for each of the page’s links.

So when you click on Next or one of the next page numbers the page’s URL changes and it opens to its own page. I need everything to stay in that main area of the “website”. Try it and you will see.

I’m not sure how to get the links to work while abiding by needing a menukey.
Can anyone offer advice on how to fix this? I am at a complete loss. No clue.

Here’s the PHP pagination file that displays in the Main Content area of that page.

// This script retrieves all the records from the users table.

echo '<h1>Customer Records:</h1>';

require_once ('mysqli_connect.php'); 	// Connect to the db.
/* Write the query...
   	Note: CONCAT_WS is a function that concatenates items together with a given separator.
	In this case, the last name and first name are added together , and separated by a comma and a space. */

$display = 20;

if (isset($_GET['p']) && is_numeric($_GET['p'])) { //Already determined.
	$pages = $_GET['p'];
										 } else { //Need to determine.
	$q = "SELECT COUNT(customerID) FROM customer";
	$r = @mysqli_query ($dbc, $q);
	$row = @mysqli_fetch_array ($r, MYSQLI_NUM);
	$records = $row[0];

if ($records > $display) {
	$pages = ceil($records/$display);
										 } else {
	$pages = 1;

if (isset($_GET['s']) && is_numeric($_GET['s'])) {
	$start = $_GET['s'];
} else {
	$start = 0;

$q = "SELECT 
	WHEN Islaptop = 0 THEN  'No'
    WHEN Islaptop = 1 THEN  'Yes'
	ELSE 'Unknown'
   END AS lap,

CustomerID AS cusID, OldCustomerID AS oldcusID, CONCAT(LastName, ', ', FirstName, ' ', MIddleName) AS name, LCASE(CONCAT(LEFT(FirstName,1), LEFT(MIddleName, 1), LastName)) AS uname, zlu_cars.Description AS car, zlu_carcolor.Description AS color, zlu_computers.Description AS comp, zlu_race.Description AS race, zlu_residence.Description AS res, zlu_birthmonth.Description AS bm

FROM customer, zlu_cars, zlu_carcolor, zlu_computers, zlu_race, zlu_residence, zlu_birthmonth
WHERE customer.CarID=zlu_cars.CarID 
And customer.CarColorID=zlu_carcolor.CarColorID
And customer.ComputerID=zlu_computers.ComputerID
And customer.RaceID=zlu_race.RaceID
And customer.ResidenceID=zlu_residence.ResidenceID
And customer.BirthMonthID=zlu_birthmonth.BirthMonthID

ORDER BY LastName ASC, FirstName ASC 
LIMIT $start, $display";

$r = @mysqli_query ($dbc, $q); // Run the query.

	// Table header.
	echo '<table align="center" cellspacing="3" cellpadding="3" width="95%" border=1>
	    <td><b>Customer ID</b></td>
		<td><b>Old Customer ID</b></td>
	    <td><b>User Name</b></td>
		<td><b>Car Color</b></td>
		<td><b>Birth Month</b></td>
	/* Fetch and print all the records:
		Fetch a result row as an associative, a numeric array, or both. 

		type - one of MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH (default).
		By using the MYSQLI_ASSOC constant this function will behave identically to the mysqli_fetch_assoc(),
		while MYSQLI_NUM will behave identically to the mysqli_fetch_row() function. The final option MYSQLI_BOTH 
		will create a single array with the attributes of both. 

		a result row as an associative, a numeric array, or both or null if there are no more rows in the result set

$bg ='eeeeee';

	while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
		$bg =($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
		echo '<tr bgcolor="' . $bg . '"><td>' . $row['cusID'] . '</td><td>' . $row['oldcusID'] . '</td><td>' . $row['name'] . '</td><td>' . $row['uname'] . '</td><td>' . $row['car'] . '</td><td>' . $row['color'] . '</td><td>' . $row['comp'] . '</td><td>' . $row['lap'] . '</td><td>' . $row['race'] . '</td><td>' . $row['res'] . '</td><td>' . $row['bm'] . '</td></tr>';

	echo '</table>'; // Close the table.
	mysqli_free_result ($r); // Free up the resources.	

mysqli_close($dbc); // Close the database connection.

if ($pages > 1) {
	echo '<br/><p>';
	$current_page =($start/$display) + 1;
	if ($current_page !=1) {
		echo '<a href="view_customerscopy.php?s=' . ($start - $display) . '&p=' .  $pages .'"> Previous </a>';
		for ($i = 1; $i <= $pages; $i++) {
			if ($i != $current_page) {
				echo '<a href="view_customerscopy.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">'.' ' . $i . ' '. '</a>';
			} else {
				echo $i . ' ';
		if ($current_page != $pages) {
			echo '<a href ="view_customerscopy.php?s=' . ($start + $display) . '&p=' . $pages . '"> Next</a>';
		echo '</p>';

You need to pass your menukey value?

echo '<a href="view_customerscopy.php?menukey='.$_GET['menukey'].'&s=' . (($display * ($i - 1))) . '&p=' . $pages . '">'.' ' . $i . ' '. '</a>';

Of course you better escape your variable $_GET[‘menukey’].


Thank you. That was it. I needed to use the $_GET function and replace the file name with the index. That makes sense. Now I need to learn a way to make all the numbers not show, so it is clean looking!