Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help - only showing one item with ajax load call to a php file #18

Open
pcout opened this issue Oct 23, 2011 · 3 comments
Open

help - only showing one item with ajax load call to a php file #18

pcout opened this issue Oct 23, 2011 · 3 comments

Comments

@pcout
Copy link

pcout commented Oct 23, 2011

Hi,

I´m having an issue with this (great by the way) plugin.
I´m calling a PHP file in the load method, like this:

$('#hiddenresult').load('filename.php',null,initPagination);

in that PHP file i´m using standard MySql and PHP, like this.
filename.php
/* ----------------------------------------------------------------------------------------------------------------------------------- /
$SQL = "SELECT.............."
$result = mysql_query($SQL);
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_object($result)) {


// my items

}
}
/
----------------------------------------------------------------------------------------------------------------------------------- */

it all goes well except from the fact that it only displays one record - the very first one.
The pagination is fine. it calculates the page numbers just fine.

What is going on ? What am i doing wrong ?.
Can you help me please ?

This is the javascript code i use on the index page.
index.php
/* ----------------------------------------------------------------------------------------------------------------------------------- /
function pageselectCallback(page_index, jq){
var new_content = $("#hiddenresult div.result:eq("+page_index+")").clone();
$("#Searchresult").empty().append(new_content);
return false;
}
function initPagination() {
var num_entries = $("#hiddenresult div.result").length;
$("#Pagination").pagination(num_entries, {
num_edge_entries: 1,
num_display_entries: 7,
callback: pageselectCallback,
items_per_page: 4,
current_page: 0,
next_text: "Próximo",
next_show_always: false,
prev_text: "Anterior",
prev_show_always: true,
ellipse_text: "...",
load_first_page: true,
show_if_single_page:false
});
}
$(document).ready(function(){
$('#hiddenresult').load('filename.php',null,initPagination);
});
/
----------------------------------------------------------------------------------------------------------------------------------- */

@LadyLoomis
Copy link

Did you every find a work around for this?

@iurisilvio
Copy link

It is not a Pagination bug. Your callback handler is wrong. With jquery.eq(n) you get just one item from your results, but you need N items (N=items_per_page).

I wrote a small gist with the correct callback. I just removed the external call and added some local data.

https://gist.github.com/379ec54bced24e079731

@LadyLoomis
Copy link

Works great! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants