PHP question pagination - php

How would I do so that the page I'm on won't be clickable?
$page = (isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : 1);
$limit = ($page - 1) * 15;
$sql = mysql_query("SELECT * FROM log LIMIT $limit, 15");
$totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM log"),0);
$totalpages = ceil($totalres / 15);
for ($i = 1; $i <= $totalpages; $i++) {
$pagination .= "$i ";
}
<p><?php echo $pagination ?></p>

if ($i == $page)
$pagination .= "$i ";
else
$pagination .= "$i ";

Just need to modify the for loop to check what the current page is.
for ($i = 1; $i <= $totalpages; $i++)
{
if ($i != $page)
$pagination .= "$i ";
else
$pagination .= " " . $i . " ";
}

With an if inside the for,
if ( $i != $page) {
//Your code.
}
else
{
//Same page.
$pagination .= " " . $page . " "
}

#RedBlueThing Has soon has I saw your post I got it to work, although I got the idea from a different stackoverflow question with a little modifying of the code.
<?php
echo "<section>";
$link = mysqli_connect("localhost", "root", "root", "user_db");
$page = (isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : 1);
$offset = 4;
$x = 5;
$limit = ($page - 1) * $offset;
$sql = mysqli_query($link,"SELECT * FROM cfp_blogs;");
$totalres = mysqli_num_rows($sql);
$totalpages = ceil($totalres / $offset);
$stmt = mysqli_query($link, "SELECT * FROM blogs LIMIT $limit, $offset;");
if($stmt->num_rows > 0){
while($obj = mysqli_fetch_object($stmt)) {
echo "<h1>$obj->title</h1>";
echo "<p>$obj->content</p>";
$stmt2 = $link->query("SELECT COUNT(id) AS Tot FROM blogs");
if($stmt2->num_rows > 0){
while ($obj2 = $stmt2->fetch_object()){
echo "<p>($obj2->Tot)</p>";
}
}
else
echo "<p>(0)</p>";
$stmt2->close();
}
}
else {
echo "<section class='error'><h1>There was a problem with the database.</h1></section>";
}
mysqli_free_result($stmt);
for ($i = $page - $x; $i < $page; $i++)
{
if ($i >= 1) {
$pagination .= "$i ";
}
}
$pagination .= " " . $i . " ";
for ($i = $page + 1; $i <= $page + $x; $i++)
{
if ($i <= $totalpages) {
$pagination .= "$i ";
}
}
/*for ($i = 1; $i <= $totalpages; $i++)
{
if ($i != $page){
$pagination .= "$i ";
}
else{
$pagination .= " " . $i . " ";
}
}*/
mysqli_close($link);
echo $pagination;
echo "</section>";
?>
The only thing I couldn't get was having a "next" or "previous" button. If anyone is up to the task of adding on those buttons, give it a shot. Other wise..... Enjoy..... :) This is my way of giving back to the stackoverflow community for helping me.

Related

Quick PHP Pagination not working

Found a working code on PHP pagination here and i am trying to integrate this code into my search engine. I tried but the pagination function doesn't seem to work please can anybody tell me what's wrong with my code and any possible fixes.
<?php
if(isset($_GET['search']))
{
$search = $_GET['search'];
$condition = '';
$query = explode(" ", $_GET["search"]);
foreach($query as $text)
{
$condition .= "question LIKE '%".SQLite3::escapeString($text)."%' OR answer LIKE '%".SQLite3::escapeString($text)."%' OR keywords LIKE '%".SQLite3::escapeString($text)."%' OR ";
}
$condition = substr($condition, 0, -4);
$sql_query = "SELECT * FROM questions WHERE " . $condition;
$result = $db->query($sql_query);
echo $sql_query;
$queryCount = "SELECT COUNT(*) as count FROM questions WHERE " . $condition;
$countRet = $db->querySingle($queryCount);
if ($countRet > 0)
{
$perpage = 1;
$start = isset($_GET['start']) ? $_GET['start']: '';
$max_pages= ceil($countRet / $perpage);
if (!$start) {
$start = 0;
$getQuery = $db->query("SELECT * FROM questions WHERE $condition LIMIT $start, $perpage");
while($row = $getQuery->fetchArray(SQLITE3_ASSOC))
{
echo '<tr><td>'.$row["question"].'</td></tr>';
}
//Pagination Codes
echo "<center>";
$prev = $start - $perpage;
$next = $start + $perpage;
$adjacent = 3;
$last = $max_pages - 1;
if ($max_pages > 1) {
//prev button
if (!$start <= 0)
{
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$prev'>Prev</a> ";
}
if ($max_pages < 7 + ($adjacent * 2)) {
$i = 0;
for ($counter = 1; $counter < 4 + ($adjacent * 2); $counter++) {
if ($i == $start) {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> ";
}
$i = $i + $perpage;
}
}
elseif ($max_pages - ($adjacent * 2) > ($start / $perpage) && ($start / $perpage) > ($adjacent * 2)) {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=0'>1</a> ";
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$perpage'>2</a> .... ";
$i = $start;
for ($counter = ($start / $perpage)+1; $counter < ($start /$perpage) + $adjacent + 2; $counter++) {
if ($i == $start) {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> ";
}
$i = $i + $perpage;
}
}
else {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=0'>1</a> ";
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$perpage'>2</a> .... ";
$i = $start;
for ($counter = ($start / $perpage) + 1; $counter <= $max_pages; $counter++) {
if ($i = $start) {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> ";
}
$i = $i + $perpage;
}
}
}
//next button
if (!($start >= $countRet - $perpage)) {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$next'>Next</a> ";
}
echo "</center>";
}
}
else
{
echo '<label>No data found</label>';
}
}
?>
The code above doesn't seem to work for some reason. I have tried to debug but cant't seem to find the error or errors. Any reasonable help would do with this. Thanks in advance.
First you set $start in your ternary logic:
$start = isset($_GET['start']) ? $_GET['start']: '';
After this, you check whether $start exists or not, and if it doesn't, you set it 0:
if (!$start) {
$start = 0;
$getQuery ...
while($row = $getQuery ...
The problem is all of your query and pagination logic is inside of this if conditional; if $GET['start'] is set, then your query and pagination logic will never trigger. And on top of this, all of your outputted <a> links do indeed send the start parameter:
<a href='pricearray.php?search=$search&submit=Search+source+code&start=$i'>
To resolve this, simply set your ternary to 0 for the failure condition, and omit the if conditional entirely:
$start = isset($_GET['start']) ? $_GET['start']: 0;
This can be seen in the following:
$start = isset($_GET['start']) ? $_GET['start']: 0;
$max_pages= ceil($countRet / $perpage);
$getQuery = $db->query("SELECT * FROM questions WHERE $condition LIMIT $start, $perpage");
while($row = $getQuery->fetchArray(SQLITE3_ASSOC))
{
echo '<tr><td>'.$row["question"].'</td></tr>';
}
//Pagination Codes
echo "<center>";
$prev = $start - $perpage;
$next = $start + $perpage;
$adjacent = 3;
$last = $max_pages - 1;
if ($max_pages > 1) {
//prev button
if (!$start <= 0)
{
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$prev'>Prev</a> ";
}
if ($max_pages < 7 + ($adjacent * 2)) {
$i = 0;
for ($counter = 1; $counter < 4 + ($adjacent * 2); $counter++) {
if ($i == $start) {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> ";
}
$i = $i + $perpage;
}
}
elseif ($max_pages - ($adjacent * 2) > ($start / $perpage) && ($start / $perpage) > ($adjacent * 2)) {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=0'>1</a> ";
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$perpage'>2</a> .... ";
$i = $start;
for ($counter = ($start / $perpage)+1; $counter < ($start /$perpage) + $adjacent + 2; $counter++) {
if ($i == $start) {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> ";
}
$i = $i + $perpage;
}
}
else {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=0'>1</a> ";
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$perpage'>2</a> .... ";
$i = $start;
for ($counter = ($start / $perpage) + 1; $counter <= $max_pages; $counter++) {
if ($i = $start) {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> ";
}
$i = $i + $perpage;
}
}
}
//next button
if (!($start >= $countRet - $perpage)) {
echo " <a href='pricearray.php?search=$search&submit=Search+source+code&start=$next'>Next</a> ";
}
echo "</center>";

PHP MySQL pagination mysqli_result() error

I'm working on pagination, but it didn't work I tried using mysqli_fetch_array and also tried mysqli_result.
Please guide me if you have some ideas.
For the pagination page I tried a method that I found but still have problem with it.
Here is the code I tried,
<?php
$conn = mysqli_connect("localhost", "root", "", "vm");
include 'paginate.php';
$per_page = 2;
$result = mysqli_query($conn, "SELECT * FROM table1");
$total_results = mysqli_num_rows($result);
$total_pages = ceil($total_results / $per_page);
if (isset($_GET['page'])) {
$show_page = $_GET['page'];
if ($show_page > 0 && $show_page <= $total_pages) {
$start = ($show_page - 1) * $per_page;
$end = $start + $per_page;
} else {
$start = 0;
$end = $per_page;
}
} else {
$start = 0;
$end = $per_page;
}
$page = intval($_GET['page']);
$tpages = $total_pages;
if ($page <= 0) {
$page = 1;
}
function paginate($reload, $page, $tpages)
{
$adjacents = 2;
$prevlabel = "‹ Prev";
$nextlabel = "Next ›";
$out = "";
// previous
if ($page == 1) {
$out .= "<span>" . $prevlabel . "</span>\n";
} elseif ($page == 2) {
$out .= "<li>" . $prevlabel . "\n</li>";
} else {
$out .= "<li>" . $prevlabel . " \n</li>";
}
$pmin = ($page > $adjacents) ? ($page - $adjacents) : 1;
$pmax = ($page < ($tpages - $adjacents)) ? ($page + $adjacents) : $tpages;
for ($i = $pmin; $i <= $pmax; $i++) {
if ($i == $page) {
$out .= "<li class=\"active\"><a href=''>" . $i . "</a></li>\n";
} elseif ($i == 1) {
$out .= "<li>" . $i . "\n</li>";
} else {
$out .= "<li>" . $i . "\n</li>";
}
}
if ($page < ($tpages - $adjacents)) {
$out .= "<a style='font-size:11px' href=\"" . $reload . "&page=" . $tpages . "\">" . $tpages . "</a>\n";
}
// next
if ($page < $tpages) {
$out .= "<li>" . $nextlabel . " \n</li>";
} else {
$out .= "<span style='font-size:11px'>" . $nextlabel . "</span>\n";
}
$out .= "";
return $out;
}
Thanks in advance.

PHP pagination page zero issue

My pagination is showing a page zero (0) when you go to page 2. Not sure why. I don't want to show a page zero.
I'll try to only show the necessary code.
Here is my code:
<?php
$rec_limit = 100;
$targetpage = "dispatch.php";
if (isset($_GET['page']))
{
$page = $_GET['page'];
$offset = $rec_limit * ($page - 1);
}
else
{
$page = 1;
$offset = 0;
}
*** $left_rec = countRecords() - ($page * $rec_limit); ***
$total_records = countRecords(); // countRecords() should be self-explanatory
$total_pages = ceil($total_records / $rec_limit); // $rec_limit is 100
$adjacents = 2;
$previousPage = $page - 1;
$nextPage = $page + 1;
$querystring = "";
$start = ($page < $adjacents ? 1 : $page - $adjacents); // <-- i think the issue is here
$beginning = 1;
$end = ($page > $total_pages - $adjacents ? $total_pages : $page + $adjacents);
foreach ($_GET as $key => $value)
{
if($key != "page") $querystring .= "$key=$value&";
}
echo "<div class="row-fluid"><div class="span2"><ul class="pager"><li>First</li>";
if ($left_rec < $rec_limit)
{
$last = $page - 1;
echo #"<li>Previous</li>";
for($i= $start; $i <= $end; $i++)
{
echo "<li " . ((($page)==$i)? "class=\"active\"" : "") . ">$i</li>";
}
}
else if($page == 0)
{
for($i= $start; $i <= $end; $i++)
{
echo "<li " . ((($page)==$i)? "class=\"active\"" : "") . ">$i</li>";
}
echo "<li>Next</li>";
}
else if ($page > 0)
{
$last = $page - 2;
echo "<li>Previous</li> ";
for($i= $start; $i <= $end; $i++)
{
echo #"<li " . ((($page)==$i)? "class=\"active\"" : "") . ">$i</li>";
}
echo "<li>Next</li>";
}
echo "<li>Last</li>";
echo '</ul></div></div>';
?>
I would really appreciate the help in removing page 0 from the application. Please disregard any typos or missing quotes. The code works with the exception of it showing page 0.
I added a picture of what the application showing page 0. It only shows page 0 when I go to page 2. After that, I no longer see page 0.
Please let me know what I have to do.
Thanks.
Some advice:
You really shouldn't suppress errors using #, instead you should be instantiating all of your variables and writing proper code.
Don't hard-code pagination into each page. Instead, wrap it in a reusable function.
Example:
// draws a menu for navigating multiple pages of content
function paginate($page, $display, $total) {
if(isset($_SERVER['QUERY_STRING']) && trim($_SERVER['QUERY_STRING']) != '') {
if(stristr($_SERVER['QUERY_STRING'], 'page=')) {
$query = '?' . preg_replace('/page=\d+/', 'page=', $_SERVER['QUERY_STRING']);
} else {
$query = '?' . $_SERVER['QUERY_STRING'] . '&page=';
}
} else {
$query = '?page=';
}
$pages = $total <= $display ? 1 : ceil($total / $display);
$self = htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'utf-8');
$first = 'first';
$prev = 'prev';
$next = 'next';
$last = 'last';
echo '<p>';
echo ($page > 1) ? "$first | $prev |" : 'first | prev |';
echo '(page ' . $page . ' of ' . $pages . ')';
echo ($page < $pages) ? "| $next | $last" : '| next | last';
echo '</p>';
}
// output example
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$display = 100;
$start = $display * $page - $display;
$total = countRecords($start, $display);
paginate($page, $display, $total);
I agree with #mister martin, but if you use this code fundamentally, try to change
$start = ($page < $adjacents ? 1 : $page - $adjacents);
To:
$start = ($page < $adjacents ? $page : $page - $adjacents);
Edited: maybe problem in undefined $left_rec, check demo. You can change $s like $_GET['page'] and as I see all works correctly.
Demo.
<?php
$rec_limit = 100;
$targetpage = "dispatch.php";
$total_records = countRecords();
// Nav part
$page = intval($_GET['page'])? $_GET['page']: 1;
$offset = $rec_limit * ($page - 1);
$total_pages = ceil($total_records / $rec_limit); // $rec_limit is 100
$adjacents = 2;
$previousPage = $page - 1;
$nextPage = $page + 1;
$start = ($page < $adjacents ? $page : $page - $adjacents); // <-- I think the issue is this line
$beginning = 1;
$end = ($page > $total_pages - $adjacents ? $total_pages : $page + $adjacents);
$uri = $_GET;
unset($uri['page']);
$querystring = http_build_query($uri);
echo '<div class="row-fluid"><div class="span2"><ul class="pager"><li>First</li>';
if($left_rec < $rec_limit && ($page > 1))
{
echo "<li>Previous</li>";
for($i= $start; $i <= $end; $i++)
{
echo "<li " . ((($page)==$i)? "class=\"active\"" : "") . ">$i</li>";
}
} else if ($page > 1)
{
echo "<li>Previous</li> ";
for($i= $start; $i <= $end; $i++)
{
echo "<li " . ((($page)==$i)? "class=\"active\"" : "") . ">$i</li>";
}
echo "<li>Next</li>";
} else {
for($i= $start; $i <= $end; $i++)
{
echo "<li " . ((($page)==$i)? "class=\"active\"" : "") . ">$i</li>";
}
echo "<li>Next</li>";
}
echo "<li>Last</li>";
echo '</ul></div></div>';
?>

PHP pagination Adjacents

I was able to create a working pagination system for my application. But the problem I am having is when a user does a search, it can/will display over 100 pages in the pagination.
I am trying to figure out how to show only like 5 on each side of the current page. I would like to create a FIRST page button, and a LAST page button, but I'll deal with that later.
So here is the first part of code that counts the records in the database table:
<?php
function countRecords()
{
// The application takes a lot of user input, which then builds a query here.
// The user input goes into a session variable called $_SESSION['where']
// I'll start with the actual query code
$sql = "SELECT COUNT(DISTINCT CONTAINER_NUMBER) AS TOTAL
FROM 'contTable'" . " WHERE (" . $_SESSION['where'] . ");";
$sqlres = #mysql_query($sql) or die();
$row = mysql_fetch_row($sqlres);
$return $row[0];
}
So code above gets the count from the table depending on the search criteria.
Here is the next piece of code that prints the grid. I'll keep it as short as possible:
function displayrecords()
{
$rec_limit = 100;
$targetpage = "containers.php";
if(isset($_GET['page']))
{
$page = $_GET['page'];
$offset = $rec_limit * ($page - 1);
}
else
{
$page = 1;
$offset = $rec_limit * ($page - 1);
}
$left_rec = countRecords() - ($page * $rec_limit);
$select = "";
$_SESSION['where'] = "";
// user input variables are here that build a variable called $_SESSION['where']
// I'll skip the code down to the query
if ($_SESSION['where'] != "") $select = "SELECT * FROM 'contTable'" . " WHERE
(" . $_SESSION['where'] . ") GROUP BY container, bol LIMIT " . $offset . ",
" . $rec_limit . ";";
}
Please excuse any typos or missing brackets and whatnot. Just know the above code works.
Now here is the code for the rest of the pagination:
$total_records = countRecords();
$total_pages = ceil($total_records / $rec_limit);
$adjacents = 5; // I just added this variable. I don't know what to do with it
$previousPage = $page - 1;
$nextPage = $page + 1;
$querystring = "";
foreach ($_GET as $key => $value)
{
if ($key != "page") $querystring .= "$key=$value&";
}
echo '<ul style="border: 0px solid red; margin: 3px;" class="pager">';
if ($left_rec < $rec_limit)
{
$last = $page - 2;
echo #"<li><a href=\"$targetpage?page=$previousPage&$querystring\">
Previous</a></li>";
for($i = 1; $i <= $total_pages; $i++)
{
echo #"<li " . ((($page+1)==$i)? "class=\"active\"" : "") . ">
$i</li>";
}
}
else if ($page == 0)
{
for($i = 1; $i <= $total_pages; $i++)
{
echo #"<li " . ((($page+1)==$i)? "class=\"active\"" : "") . ">
$i</li>";
}
echo #"<li>Next</li>";
}
else if ($page > 0)
{
$last = $page - 2;
echo #"<li><a href=\"$targetpage?page=$previousPage&$querystring\">
Previous</a></li> ";
for($i = 1; $i <= $total_pages; $i++)
{
echo #"<li " . ((($page+1)==$i)? "class=\"active\"" : "") . ">
$i</li>";
}
echo #"<li>Next</li>";
}
echo '</ul>';
}
So, with all of the code above, I can display a grid, and display the pages at the bottom of the application. But I don't want to show all 100 pages, only 5 on each side of the current page. I know I need to utilize the variable called $adjacents and plug it in to the paging portion of the code. But I'm not exactly sure how to do it.
I hope I am being clear on my request.
Please help.
Instead of looping through all of the pages:
for($i = 1; $i <= $total_pages; $i++)
Try doing something like this:
$start = ($page < $adjacents ? 1 : $page - $adjacents);
$end = ($page > $total_pages - $adjacents ? $total_pages : $page + $adjacents);
for($i= $start; $i <= $end; $i++)
//Here you can loop through the numbers within adjacents of the current page

Href format using master page php

I saw a similar post on stackoverflow but it failed to anwser my question.
I am using pagination to display results and the link is coming up broken when I add the master links. Most likely as I am incorrectly using the correct format.
Have tried a few formats to try to get it working based on other posts
<a href='../admin/admin.master.php?page=list_products.php&page=' .$j. ' id='page_a_link'>Next</a></span>
or
../admin/admin.master.php?page=list_products.php&page=$j
but neither work.
PHP PAGINATION SHOWING PAGE NUMBERS
<?php
if(isset($page))
{
$result = mysql_query("SELECT COUNT(*) As Total FROM products");
$rows = mysql_num_rows($result);
if($rows)
{
$rs = mysql_fetch_array($result);
$total = $rs["Total"];
}
$totalPages = ceil($total / $perpage);
if($page <=1 )
{
echo "<span id='page_links' style='font-weight:bold;'>Pre</span>";
}
else
{
$j = $page - 1;
echo "<span><a id='page_a_link' href='../admin/admin.master.php?page=list_products.php&page=$j'>< Pre</a></span>";
}
for($i=1; $i <= $totalPages; $i++)
{
if($i<>$page)
{
echo "<span><a href='../admin/admin.master.php?page=list_products.php&page=' .$i. ' id='page_a_link'>$i</a></span>";
}
else
{
echo "<span id='page_links' style='font-weight:bold;'>$i</span>";
}
}
if($page == $totalPages )
{
echo "<span id='page_links' style='font-weight:bold;'>Next ></span>";
}
else
{
$j = $page + 1;
echo "<span><a href='../admin/admin.master.php?page=list_products.php?page=' .$j. ' id='page_a_link'>Next</a></span>";
}
}
?>
You are mixing double quotes with single quotes, that's why it breaks. Try this:
<?php
if(isset($page))
{
$result = mysql_query("SELECT COUNT(*) As Total FROM products");
$rows = mysql_num_rows($result);
if($rows)
{
$rs = mysql_fetch_array($result);
$total = $rs["Total"];
}
$totalPages = ceil($total / $perpage);
if($page <=1 )
{
echo '<span id="page_links" style="font-weight:bold;">Pre</span>';
}
else
{
$j = $page - 1;
echo '<span><a id="page_a_link" href="../admin/admin.master.php?page=list_products.php&page=' . $j . '">< Pre</a></span>';
}
for($i=1; $i <= $totalPages; $i++)
{
if($i<>$page)
{
echo '<span>' . $i . '</span>';
}
else
{
echo '<span id="page_links" style="font-weight:bold;">' . $i . '</span>';
}
}
if($page == $totalPages )
{
echo '<span id="page_links" style="font-weight:bold;">Next ></span>';
}
else
{
$j = $page + 1;
echo '<span>Next</span>';
}
}
?>
Also, the HTML code you generate isn't valid, as you assign the same ID to multiple elements. Consider changing id="page_links" and id="page_a_link" to class="page_link" and class="page_a_link" respectively, then change #page_links and #page_a_link in your CSS to .page_links and .page_a_link
You are assigning two values to page in the URL '../admin/admin.master.php?**page**=list_products.php&**page**=' .$j. ' try replacing page = $j with page_num = $j or something of your choice and replace it in the and in the code.

Categories