Log in

View Full Version : jquery pagination with php



sumantapaul123
01-31-2009, 06:07 PM
If there is any one can solve my problem

i have two file
one is
index.html
code is
<?php
error_reporting( E_ALL );
$conn = mysql_connect( 'localhost', 'root', '');
if ( is_resource( $conn ) ) {
if ( !mysql_select_db('db155735726', $conn) ) {
echo '<p>Can not select db.</p>';
}

$sql = 'SELECT COUNT(*) from news;';
$res = mysql_query($sql);
if ( is_resource( $res ) ) {
$total = mysql_result( $res, 0 );

}

}

?>
<html>
<head>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.pagination.js"></script>
<script type="text/javascript">
function pageselectCallback(page_id, jq){
var first = (page_id*10)+1, second = (page_id*10)+5;
$('#Searchresult').text("Showing search results " + first + '-' + second);
$.ajax({
type:'GET',
url:'ajax.php',
data:'offset=' + first + '&limit=5',
success:function(msg) {
$('#ajaxContent').html(msg);
}
});
}
$(document).ready(function(){
$("#Pagination").pagination( <?php echo $total;?>, {
num_edge_entries: 2,
num_display_entries: 8,
callback: pageselectCallback
});

pageselectCallback(0);
});
</script>

</head>
<body>
<div id="Pagination">

</div><br clear="all"/>
<div id="Searchresult">
</div>
<div id="ajaxContent"> <table border="2">
<tr>
<th > date</th>
<th > germanText</th>
<th > englishText</th>
<th > germanTitle</th>
<th > englishTitle</th>
</tr>
<tbody>
<tr>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
</tr>
<tr>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
</tr>
<tr>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
</tr>
<tr>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
</tr>
<tr>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
</tr>
<tr>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
</tr>
<tr>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
</tr>
<tr>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
<td>static elements</td>
</tr>
</tbody>
</table> </div>
</body>
</html>

other one is
ajax.php
code like
<?php
$offset = $_GET['offset'];
$limit = $_GET['limit'];
$conn = mysql_connect( 'localhost', 'root', '');
if ( is_resource( $conn ) ) {
if ( !mysql_select_db('db155735726', $conn) ) {
echo '<p>Can not select db.</p>';
}
$result = mysql_query('SELECT * from NEWS LIMIT ' . $offset . ',' . $limit);
if ( is_resource( $result ) ) {

while ( $row = mysql_fetch_assoc( $result ) ) {

echo $row['date'];
echo $row['germanText'] ;
echo $row['englishText'];
echo $row['germanTitle'] ;
echo $row['englishTitle'] ;
}


}
}
?>

it works fine
but i want to display result in tabuler format
if any one can solve my problem please help me