i am a php n00b.
I am trying to figure out how to paginate a page that has a url of
http://localhost/artistpage.php?show=A222222
the links come out the way i want them but
it only echos out the limit of 25 and when i click to go to the next page, i get the formatted page but i do not get any results
some other posts said sumthin bout session vars or sumthin but i dont know
this is what i've gotten so far (stripped out some of the garbage)
any help or links would be cool
/////////////////////gets artid from previous page/////////
///////////////////////////////////////////////////////////////////////
if (isset($_GET["show"]))
$show = $_GET["show"];
else
$show = "";
///////////////////////pagination part/////////////////////
/////////////////////////////////////////////////////////////////
$rowsPerPage = 25;
//show at start
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
/////////////////query to display data////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
$query = "SELECT * FROM track WHERE artid LIKE '".$show."%' ORDER BY title LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
showing artist data no problem
}
///////////////////finding the num of pages with be in the pagination///////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$count[0] = mysql_query("SELECT COUNT(*) FROM track WHERE artid LIKE '".$show."%'");
$countdata[0] = mysql_fetch_row($count[0]);
//totals out to what is there correctly no prob
echo $countdata[0][0];
$numrows = $countdata[0][0];
$maxPage = ceil($numrows/$rowsPerPage);
////////////////////printing the link to access each page/////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"$self?show=".$show."?page=$page\">$page</a> ";
}
}
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?show=".$show."?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?show=".$show."?page=1\">[First Page]</a> ";
}
else
{
$prev = ' ';
$first = ' ';
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?show=".$show."?page=$page\">[Next]</a> ";
$last = " <a href=\"$self?show=".$show."?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $first . $prev . $nav . $next . $last;