/    Sign up×
Community /Pin to ProfileBookmark

jQuery Pagination and MySQL $limit, $offset

I am trying to use the jQuery pagination plugin with my PHP/MySQL website — [B] It appears I have to either use Ajax or use PHP to write the jQuery pagintion header so I can control the $offset and $limit[/B], in order to control the pagination —

What is the best way to combine javascript, PHP and MySQL so that they can communicate with eachother? Here is my PHP page and SQL

[code=html]
<script type=”text/javascript” src=”include/jquery-latest.js”></script>
<script type=”text/javascript” src=”include/tablesorter/addons/pagination/jquery.pagination.js”></script>
<link rel=”stylesheet” href=”include/tablesorter/addons/pagination/pagination.css” type=”text/css” media=”print, projection, screen” />
<script type=”text/javascript”>

function pageselectCallback(page_id, jq){
$(‘#Searchresult’).text(“Showing search results “+((page_id*10)+1)+”-“+((page_id*10)+10));
}

$(document).ready(function(){
// Create pagination element
$(“#Pagination”).pagination(300, {
num_edge_entries: 2,
num_display_entries: 8,
callback: pageselectCallback
});
});

</script>

<div id=”Pagination” class=”pagination”></div>

<br style=”clear:both;” />
<div id=”Searchresult”>
Showing search results 1-10 …
</div>

<?php

$limit = 10;
$offset = 0;

dbConnect();
$sql = “SELECT * FROM emt_company LIMIT $offset, $limit”;
$result = mysql_query($sql) or die(mysql_error());
$num = mysql_num_rows($result);

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

$name = $row[‘name’];
echo “$name<br>”;

}

?>
[/code]

to post a comment
JavaScript

1 Comments(s)

×

Success!

Help @ripcurlksm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...