Jump to content
php.lv forumi

page pagination


Recommended Posts

Tātad gribu uztaisīt page pagination lai pārlādetu komentāru lapu bez refresh.

 

php daļa

if(!isset($_GET['page'])){
  $lapa = 1;
} else {
  $lapa = $_GET['page'];
}
$max_results = 3;
$from = (($lapa * $max_results) - $max_results);
$c_c = mysql_query("SELECT * FROM c_c WHERE n_id = '".stripslashes($_GET['id'])."' ORDER BY id ASC LIMIT $from, $max_results");
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM c_c"),0);
$total_pages = ceil($total_results / $max_results);
if(mysql_num_rows($c_c) == 0){ echo '<div style="width: 460px; height: auto; background: none repeat scroll 0% 0% rgb(255, 255, 255); float: left; margin: 2px; border: 1px solid rgb(221, 221, 221); -moz-border-radius: 3px 3px 3px 3px;"><div style="padding-left: 10px; margin: 0px auto;"><table><tbody><tr><td style="width: 200px;">No comments about <b>'.$row['title'].'</b>.</td></tr></tbody></table></div></div>'; } else {

while($c = mysql_fetch_array($c_c)){
$coum = substr_replace($c['com'], '<br/>',65, 66);
echo '<div id="comm">
		<div class="title"><div style="float: left;"><a href="/?p=user&id='.$c['a_id'].'">'.$c['who'].'</a> @  '.$c['when'].'</div><div style="float: right;">  </div><br style="clear: both;"></div>
		<div class="text">'.nl2br($coum).'</div></div><br>
'; }
echo "<br/><table width='100%' align='left'><tr><td><div id='news_container'><div id=\"pages\">";
if($lapa > 1){
  $prev = ($lapa - 1);
  echo '<a href=\'javascript:;\' onclick=\'news_page("'.$prev.'", "")\'>«</a>';
}
for($i = 1; $i <= $total_pages; $i++){
  if(($lapa) == $i){
      echo "<span class=\"current\"><b>".$i."</b></span>";
      } else {
          echo "<a href='javascript:;' onclick='news_page(\"".$i."\", \"\")'>$i</a>";
  }
}
if($lapa < $total_pages){
  $next = ($lapa + 1);
  echo "<a href='javascript:;' onclick='news_page(\"".$next."\", \"\")'>»</a>";
}
echo "</div></div></td></tr></table>
"; }

 

js daļa

function news_page(page, search) {
$("#news_container").mask("Loading..");
$.get("/pages/news.php?id=<?php echo $_GET['id']; ?>&page=",
{ page: page
},
function(response){
$("#news_container").html(response);
$("#news_container").unmask();
});
}

 

Problēma ir tada - kad spiež uz citu lapu neko neielādē..

Edited by chizijs
Link to post
Share on other sites

varbūt debugo, skaties, kas notiek, kas nē? Kur ir problēma? Baigi jau mums no malas te gribās tādā milzīgā koda blāķī iedziļināties un meklēt problēmu...

 

Ko rāda JS kļūdu konsole?

Link to post
Share on other sites
Guest
This topic is now closed to further replies.
×
×
  • Create New...