Afisare rezultate paginate la scroll page

Discutii si intrebari legate de scripturi si functii JavaScript, jQuery si Ajax, cod JavaScript in general.
Avatar utilizator
evident
Mesaje:168

Afisare rezultate paginate la scroll page

Salut,
In baza de date am 23 de rezultate din care initial afisez doar 10 si as vrea ca atunci cand ajung cu scroll la finalul paginii sa imi afiseze inca 10 pana le afiseaza pe toate.Am facut scriptul asta doar ca afiseaza doar primele 10 si atat...unde gresesc?Multumesc!
afisare.php

Cod: Selectaţi tot

<style>
.question {font-weight:bold;background-color:#FFF;padding:7px 0px  0px 15px;}
.answer{font-style:italic;background-color:#FFF;padding:0px 0px 7px 15px;}
#faq-result{margin: -10px auto 0px;width:50%;line-height:30px;border-radius:5px;min-height:300px;}
#loader-icon {position: fixed;top: 50%;width:100%;height:100%;text-align:center;display:none;}
</style>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.2.6.pack.js"></script>
<script>
$(document).ready(function(){
	function getresult(url) {
		$.ajax({
			url: url,
			type: "GET",
			data:  {rowcount:$("#rowcount").val()},
			beforeSend: function(){
			$('#loader-icon').show();
			},
			complete: function(){
			$('#loader-icon').hide();
			},
			success: function(data){
			$("#faq-result").append(data);
			},
			error: function(){} 	        
	   });
	}
	$(window).scroll(function(){
		if ($(window).scrollTop() == $(document).height() - $(window).height()){
			if($(".pagenum:last").val() <= $(".total-page").val()) {
				var pagenum = parseInt($(".pagenum:last").val()) + 1;
				getresult('script_afisare.php?page='+pagenum);
			}
		}
	}); 
});
</script>
</HEAD>
<BODY>
<div id="faq-result">
<?php include('script_afisare.php'); ?>
</div>
<div id="loader-icon"><img src="LoaderIcon.gif" /><div>
</BODY>
</HTML>
script_afisare.php

Cod: Selectaţi tot

<?php
include"header.php";
require_once("include/functii.php");

$perPage = 10;

$page = 1;
if(!empty($_GET["page"])) {
$page = $_GET["page"];
}

$start = ($page-1)*$perPage;
if($start < 0) $start = 0;

$mydb->setQuery("SELECT * from php_interview_questions limit $start,$perPage");
$faq = $mydb->executeQuery();
$nr = $mydb->num_rows($faq);

if(empty($_GET["rowcount"])) {
$_GET["rowcount"] = $nr;
}
$pages  = ceil($_GET["rowcount"]/$perPage);
$output = '';
if(!empty($faq)) {
$output .= '<input type="hidden" class="pagenum" value="' . $page . '" /><input type="hidden" class="total-page" value="' . $pages . '" />';
while($row = $faq->fetch_assoc()){
  $output .=  '<div class="question">' . $row["question"] . '</div>';
  $output .= '<div class="answer">' . $row["answer"] . '</div>';
}

print $output;

}
?>

MarPlo
Nu functioneaza findca ai definit functiile in ready().
Incearca scriptul js asa (daca nu functioneaza, verifica in consola browserului de eventuale erori js).

Cod: Selectaţi tot

<script>
function getresult(url) {
  $.ajax({
    url: url,
    type: 'GET',
    data:  {rowcount:$("#rowcount").val()},
    beforeSend: function(){
      $('#loader-icon').show();
    },
    complete: function(){
      $('#loader-icon').hide();
    },
    success: function(data){
      $("#faq-result").append(data);
    },
    error: function(){} 	        
  });
}

$(window).scroll(function(){
  if ($(window).scrollTop() == $(document).height() - $(window).height()){
    if($(".pagenum:last").val() <= $(".total-page").val()) {
      var pagenum = parseInt($(".pagenum:last").val()) + 1;
      getresult('script_afisare.php?page='+pagenum);
    }
  }
});
</script>
In plus, in cod ai $("#rowcount").val(), dar in codul html nu ai un input cu id #rowcount, iar acea valoare o preiei si in php, dar lipseste in html.

evident
Am rezolvat(era o litera gresit apasata pe acolo), imi merge scriptul, dar a mai aparut o eroare.
Eu am 21 de inregistrari in baza de date.
Daca pun $perPage = 2; imi afiseaza inregistrarea 1 si 2 iar cand ajung la capatul paginii imi afiseaza 3 si 4 iar apoi cand ajung iar la capatul paginii nu imi mai afiseaza nimic, scriptul se opreste acolo.
Aveti idee ce poate fi?
Multumesc!

Subiecte similare