Jump to content

issue with pagination. after the first page no entries are listed.


digitalmartyr

Recommended Posts

so i have a catalog for user to view, to make it more friendly its broken down using pagination. it works, it breaks the entries into sets of 9 on every page. but information is only displayed on the first page. if you click next or previous, you get no entires. here is my code below, if someone can take a look at id be very greatful.

 

thanx

 

<?php
require('dbconnect.php');
//
if($_GET['page'])
{
$pagesection = $_GET['page'];
}
if(isset($_GET['cat']))
{
$prodCat = $_GET['cat'];
echo "<br />";
echo "Category: ".$prodCat;
}
//
$pagenum = $_GET['pagenum'];

if (empty($pagenum) || !is_numeric($pagenum))
{ 
$pagenum = 1;
}
else
{
$pagenum = $_GET['pagenum'];
}


//make sure page number isnt below 1 or more than maxpages
//get sql results and count
//see what cat is called
if($prodCat == 'all')
{
$data = "SELECT * FROM products";	
$query = mysql_query($data)or die(mysql_error());
}
else
{
$data = "SELECT * FROM products WHERE category = '$prodCat'";
$query = mysql_query($data)or die(mysql_error());
}
$rows = mysql_num_rows($query);
//number of results per page
$page_rows = 9;

//tells the page number of our last page
$last = ceil($rows/$page_rows);


//sets the range to display in our query

$max = ' LIMIT '.($pagenum-1) * $page_rows.','.$page_rows;
$limit = (($pagenum - 1) * $page_rows);
echo "limit ".$limit;
echo "pagenum ".$pagenum;
echo "pagerow ".$page_rows;
$maxquery = $data.$max;
$qdata = mysql_query($maxquery)or die(mysql_error());
//run query to display results *style for display* 
//add $max to it for limiting result
echo "<table>";

// initiate counter
$i = 0;

while($info = mysql_fetch_array($qdata))
{
$html  = '<div id="productThumb">';
$html .= '<h3>product id: '.$info['product_id'].'</h3>';
$html .= '<h2>product name: '.$info['product_name'].'</h2>';
$html .= '<img height="140" width="100" src="'.$info['product_img'].'"</img>';
$html .= '<br />';
$html .= '<span>Product Describtion '.$info['product_dscrb'].'</span>';
$html .= "<a href='{$_SERVER['PHP_SELF']}?product_id=".$info['product_id']."&page=editprod'>edit</a>";
$html .= '</div>';

    if(($i + 1) % 3 == 1){
        echo "<tr><td>$html</td>";
    } elseif(($i + 1) % 3 == 2){
        echo "<td>$html</td>";
    } elseif(($i + 1) % 3 == 0){
        echo "<td>$html</td></tr>";
    }

    // increment counter
    $i++;

    // unset html var
    unset($html);
}

echo "</table>";

//shows user what page they are on and the total number of pages
echo "<p>--page $pagenum of $last--<p>";

//check if on page 1, if so we dont need a link to the prev page or first page so do nothing
//if we arent on page 1 we generate links to the first page and to the prev pages
if($pagenum == 1)
{

}
else
{
echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=1'>
<<-First</a>";
echo " ";
$previous = $pagenum-1;
echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$previous'>
<-Previous</a>";
}

//this does the same above, only checking to see if we are on the last page
//and then generating the NExt and Last link
if($pagenum == $last)
{

}
else
{
$next = $pagenum+1;
echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$next'>Next-></a>";
echo " ";
echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$last'>Last->></a>";
}
?>

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.