0

I need some help regarding pagination. whenever i searched for a record, the pagination doesnt work but it still show the results. here are my codes


index.php

<html>
	<head>
		<title>Paginating Your Data with AJAX and Awesome PHP Pagination Class</title>
<form action="index.php" method="post" name="searchdb" id="searchdb">
<table>
<tr>
<td><tr>
<input type="text" name="searchdb" id="searchdb" size="25" />&nbsp;
<input type="submit" name="submit" id="submit" value="Go!" /></td>
</p></tr>
</table>
</form>	
	</head>

<body>

<div id='retrieved-data'>
	<!-- 
	this is where data will be  shown
	-->
    <img src="images/ajax-loader.gif" />
</div>

<script type = "text/javascript" src = "js/jquery-1.4.js"></script>
<script type = "text/javascript">
$(function() {
	//call the function onload
	getdata( 1 );
});

function getdata( pageno ){

                    
	var targetURL = 'search_results.php?page=' + pageno;   

	$('#retrieved-data').html('<p><img src="images/ajax-loader.gif" /></p>');        
	$('#retrieved-data').load( targetURL ).hide().fadeIn('slow');
}      
</script>

</body>
</html>

search_results.php

<!-- include style -->
<link rel="stylesheet" type="text/css" href="styles/style.css" />
<?php
//open database
include 'config_open_db.php';
//include our awesome pagination
//class (library)
include 'libs/ps_pagination.php';

//query all data anyway you want


$searchdb = $_POST['searchdb'];

// make the query


$sql = "SELECT * from employer
WHERE username LIKE '%$searchdb%' order by user_id";
//$result = @mysql_query($query); // run query



//if ($searchdb) {

//$sql = "select * from employer ORDER BY username DESC";

//execute query and get and

$rs = mysql_query( $sql ) or die('Database Error: ' . mysql_error() . ' ' . $sql );

//now, where gonna use our pagination class
//this is a significant part of our pagination
//i will explain the PS_Pagination parameters
//$conn is a variable from our config_open_db.php
//$sql is our sql statement above
//3 is the number of records retrieved per page
//4 is the number of page numbers rendered below
//null - i used null since in dont have any other
//parameters to pass (i.e. param1=valu1&param2=value2)
//you can use this if you're gonna use this class for search
//results since you will have to pass search keywords
$pager = new PS_Pagination( $conn, $sql, 3, 4, null );

//our pagination class will render new
//recordset (search results now are limited
//for pagination)
$rs = $pager->paginate(); 

//get retrieved rows to check if
//there are retrieved data
$num = mysql_num_rows( $rs );

if($num >= 1 ){     
	//creating our table header
	echo "<table id='my-tbl'>";
	echo "<tr>";
		echo "<th>UsernameFirstname</th>";
		echo "<th>Lastname</th>";
		echo "<th>Firstname</th>";
	echo "</tr>";
	
	//looping through the records retrieved
	while($row = mysql_fetch_array( $rs )){
		echo "<tr class='data-tr' align='center'>";
		echo "<td>{$row['username']}</td>";
		echo "<td>{$row['lastname']}</td>";
		echo "<td>{$row['firstname']}</td>";
		echo "</tr>";
	}       
	
	echo "</table>";
}else{
	//if no records found
	echo "No records found!";
}
//page-nav class to control
//the appearance of our page 
//number navigation
echo "<div class='page-nav'>";
	//display our page number navigation
	echo $pager->renderFullNav();
echo "</div>";

?>
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by debasisdas
0

But i don't understand what pagination has to do with database design. That should be handled at application level.

Edited by debasisdas: n/a

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.