Jump to content

[SOLVED] Page Split on Mysql Return


tecksiez

Recommended Posts

Hello, I'm having an issue with my page splits when pulling information from my database, the first page displays the information correctly however when you click on "Next Page" or "page 2" it pulls all data from the database. It's acting as if it's not passing the variable $search through to the next page.

 

This is my page that displays the results I'll leave the html portion out:

<?
	require('db.php');
	require('pagesplit.php');
// connect to the database and insert the information
	$search = $_POST['search'];		
	$sql = "SELECT * FROM $table 
			WHERE id 
			LIKE '%$search%' 
			OR fname 
			LIKE '%$search%' 
			OR lname 
			LIKE '%$search%' 
			OR time 
			LIKE '%$search%' 
			OR ext 
			LIKE '%$search%' 
			OR ltag 
			LIKE '%$search%' 
			OR depts 
			LIKE '%$search%' 
			OR probs 
			LIKE '%$search%' 
			OR loca 
			LIKE '%$search%' 
			OR tech 
			LIKE '%$search%' 
			OR status 
			LIKE '%$search%' 
			OR priority 
			LIKE '%$search%' 
			ORDER BY id DESC 
			LIMIT $offset, $rowperpage";

	$snag = mysql_query($sql, $connection) or die(mysql_error());

require('display.php');

?>

 

here is the page split:

 

<?
// How many rows to display per page.
$rowperpage = 20;

// Default to show page one
$pagenum = 1;

// Define $_GET['page'] , and use it as a page number
if(isset($_GET['page']))
{
	$pagenum =$_GET['page'];
}

//count the offset
$offset = ($pagenum - 1) * $rowperpage;

// how many rows we have in database
$query   = "SELECT COUNT(id) AS numrows FROM $table";
$result  = mysql_query($query) or die('Error, query failed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowperpage);

// print the link to access each page
$self = $_SERVER['PHP_SELF'];

if ($pagenum > 1)
{
   $page  = $pagenum - 1;
   $prev  = " <a href=\"$self?page=$page\">[Prev]</a> ";

   $first = " <a href=\"$self?page=1\">[First Page]</a> ";
} 
else
{
   $prev  = ' '; // we're on page one, don't print previous link
   $first = ' '; // nor the first page link
}

if ($pagenum < $maxPage)
{
   $page = $pagenum + 1;
   $next = " <a href=\"$self?page=$page\">[Next]</a> ";

   $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
} 
else
{
   $next = ' '; // we're on the last page, don't print next link
   $last = ' '; // nor the last page link
}

?>

Then in the footer it just echos the links for $next and $last etc...

 

Any help would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/107483-solved-page-split-on-mysql-return/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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