PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$query = "SELECT COUNT(id) AS numrows FROM products WHERE pause = 'off' AND rcstock <> 'out of stock'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = min(160, $row['numrows']);
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " <div class='pagelinkactive'>$page</div> "; // no need to create a link to current page
}
else
{
if ($page == "1")
{
$nav .= " <a href=\"/productsnew\" class='pagelink'>$page</a>";
}
else
{
$nav .= " <a href=\"/productsnew/page/$page\" class='pagelink'>$page</a>";
}
}
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"/productsnew/page/$page\" class='pagelink'>Prev</a> ";
$first = " <a href=\"/productsnew\" class='pagelink'>First Page</a>";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"/productsnew/page/$page\" class='pagelink'>Next</a>";
$last = " <a href=\"/productsnew/page/$maxPage\" class='pagelink'>Last Page</a>";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo "<div class='navpages'>" . $first . $prev . $nav . $next . $last . "</div>";
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
That's got it. Just couldnt' quite grasp how to do it in PDO.
PS that 'function' we worked on is working an absolute treat!
Some tech guys ran a crawler for us to generate all the images.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Trouble is, easy one of these is different, depending on the page (finding different data). So wouldn't really serve much of a purpose.
Unless I had a function to do them all, and each page just give it different things to query on, but then the variables will also differ.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
I don't know enough about how they're implemented. Just looks like it'd be ripe for abstracting away as I suspect each variation of this is more the same than different.
simonmlewis wrote:Trouble is, easy one of these is different, depending on the page (finding different data). So wouldn't really serve much of a purpose.
Unless I had a function to do them all, and each page just give it different things to query on, but then the variables will also differ.