Jump to content

[SOLVED] paging?


adamlacombe

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.