php - Pagination Database Query Woes -
i have been working @ day , still @ 8pm have had no luck. wondering if guys can give me advice on fixing it. building upload - gif sharing system university.
here code anyway -
<?php ini_set('display_errors',1); error_reporting(e_all); mysql_connect("localhost","root","root") or die("top query"); mysql_select_db("upload") or die(mysql_error()); $count_query = mysql_query("select null details"); $count = mysql_num_rows($count_query); //pagination if(isset($_get['page'])){ $page = preg_replace("#[^0-9]#","",$_get['page']); }else{ $page= 1; } $perpage = 5; $lastpage = ceil($count / $perpage); if($page < 1){ $page = 1; }else if($page > $lastpage){ $page = $lastpage; } $limit = "limit " .($page -1) * $perpage . ", $perpage"; //query , gifs $query = mysql_query("select * details order date_added desc") or die("2nd query"); //puts array $pagination=""; if($lastpage != 1){ if($page != $lastpage){ $next = $page + 1; $pagination.='<a href="index.php?page='.$next.'">more</a>'; } if($page != 1){ $prev = $page - 1; $pagination.='<a href="index.php?page='.$prev.'">back</a>'; } } ?>
and output in html -
<?php while($info = mysql_fetch_array($query)){ $shortlink = "<a href=uploads/".$info['photo'].">".$info['photo']." </a>" ; //outputs image , other data echo "<article class='upload-post'>" . "<div class='crop'>"; echo "<a href=uploads/".$info['photo'].">"; echo "<img class='scale-with-grid' src=uploads/".$info['photo'] .">"."</a>"; echo "</div>"; echo "".$info['name'] . "<br/>"; echo "reaction ".$info['reaction'] ."<br/>"; echo "in " .$info['category'] ." <br/>"; echo "on " .$info['date_added'] ." <br/>"; echo "link: $shortlink"; echo "</article>"; } ?> <?php echo $pagination;?>
i can toggle between pages not limiting number of posts displayed on page. id appreciate deadline isn't far away. bunch in advance!
you never append $limit
query.
Comments
Post a Comment