adamlacombe Posted June 26, 2009 Share Posted June 26, 2009 I have this: <?php $cat=$_GET['cat']; print "<table class='maintable'>"; $gamecat="SELECT * from game where game_cat='$cat' LIMIT 0,30"; $gamecat2=mysql_query($gamecat) or die("Could not get cat"); while($gamecat3=mysql_fetch_array($gamecat2)) { print "<a href='index.php?action=game&id=$gamecat3[game_id]'>$gamecat3[game_name]</a><br />"; } print "</table>"; ?> Is there a way to make it so It will have pages? like pages 1,2,3,4,5, etc... if so how? thanks in advanced! Quote Link to comment https://forums.phpfreaks.com/topic/163786-solved-paging/ Share on other sites More sharing options...
kickstart Posted June 26, 2009 Share Posted June 26, 2009 Hi Something like this <?php $cat=$_GET['cat']; $page=$_GET['pageNo']; if ($page < 1) $page = 1; print "<table class='maintable'>"; $gamecat="SELECT * from game where game_cat='$cat' LIMIT ".($page-1) * 5).",".(($page * 5) -1); $gamecat2=mysql_query($gamecat) or die("Could not get cat"); while($gamecat3=mysql_fetch_array($gamecat2)) { print "<a href='index.php?action=game&id=$gamecat3[game_id]'>$gamecat3[game_name]</a><br />"; } print "</table>"; $gamecount="SELECT COUNT(*) as TotCount from game where game_cat='$cat'"; $gamecount2=mysql_query($gamecount) or die("Could not get cat"); if($gamecount3=mysql_fetch_array($gamecount2)) { for($iCnt = 1;$iCnt <= $gamecount3['TotCount'];$iCnt++) { print (($iCnt == $page) ? " $iCnt " : " <a href='ThisPage.php?cat=$cat&page=$iCnt'>$iCnt</a> "); } } ?> All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/163786-solved-paging/#findComment-864199 Share on other sites More sharing options...
adamlacombe Posted June 26, 2009 Author Share Posted June 26, 2009 Well that comes arossed as an error but i found something and have this now: <?php $cat=$_GET['cat']; $records_per_page = 20; $total = mysql_result(mysql_query("SELECT COUNT(*) FROM game WHERE game_cat='$cat'"), 0); $page_count = ceil($total / $records_per_page); $page = 1; if (isset($_GET['page']) && $_GET['page'] >= 1 && $_GET['page'] <= $page_count) { $page = (int)$_GET['page']; } $skip = ($page - 1) * $records_per_page; $result = mysql_query("SELECT * FROM game WHERE game_cat='$cat' LIMIT $skip, $records_per_page"); echo "<table border=1>"; while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><a href='index.php?action=game&id=$row[game_id]'>$row[game_name]</a></td>"; echo "</tr>"; } echo "</table>"; for ($i = 1; $i <= $page_count; ++$i){ echo '<a href="index.php?action=browse&cat=$cat&page=' . $i . '">' . $i . '</a> '; } ?> but this: for ($i = 1; $i <= $page_count; ++$i){ echo '<a href="index.php?action=browse&cat=$cat&page=' . $i . '">' . $i . '</a> '; } where the page links are has $cat in there, its not recognizing it as $cat=$_GET['cat']; any idea why? Quote Link to comment https://forums.phpfreaks.com/topic/163786-solved-paging/#findComment-864203 Share on other sites More sharing options...
adamlacombe Posted June 26, 2009 Author Share Posted June 26, 2009 got it.. DUH '.$cat.' lol Quote Link to comment https://forums.phpfreaks.com/topic/163786-solved-paging/#findComment-864208 Share on other sites More sharing options...
fenway Posted June 27, 2009 Share Posted June 27, 2009 Just remember that paging that way will be VERY slow as soon as the offset and/or the result set get large. Quote Link to comment https://forums.phpfreaks.com/topic/163786-solved-paging/#findComment-864772 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.