Jump to content

Adding pagination to existing product pages


nomeaning

Recommended Posts

Hi there, I've been trying to implement pagination to an existing script that displays products, but at present only displays next and back buttons.  The number of products is now increasing and we would like to show the number of pages of results but the tutorials I've been going through seem to use a very different way of displaying the results to the script we currently have. Does anyone have any suggestions how I could add pagination to this form.....

 

        // Build Pagination

$ByPage = ($prod_rows * $prod_cols);

 

$qnav = "SELECT devbg_products.*, devbg_categories.*, devbg_subcategories.* FROM devbg_products

        LEFT JOIN devbg_categories ON devbg_products.ItemCategory = devbg_categories.CategoryID

        LEFT JOIN devbg_subcategories ON devbg_products.ItemSubcategory = devbg_subcategories.SubcategoryID

        WHERE devbg_products.ItemCategory = " . sql($cgid);

 

        $rnav = mysql_query($qnav) or die(mysql_error());

        $rows = mysql_num_rows($rnav);

 

        if($rows > $ByPage)

        {

                $pages = ceil ($rows / $ByPage);

 

 

                echo "<br>\n";

                echo "<table align='center'>\n";

                echo "<tr>\n";

                echo "<td align=center><font face=verdana size=2>";

                echo "<form method='POST' action='ShowCategory.php'>\n";

                echo "<input type='hidden' name='Start' value='" . ($Start - $ByPage) . "'>\n";

                echo "<input type='hidden' name='CategoryID' value='" . $_REQUEST["CategoryID"] . "'>\n";

                echo "<input type='hidden' name='SubcategoryID' value='" . $_REQUEST["SubcategoryID"] . "'>\n";

 

                if (($Start - $ByPage) <> -$ByPage)

                {

                        echo "<input class='sub' type='submit' value='<<< Back' name='btnBack'>\n";

                        echo "</form>\n";

                        echo "</td>\n";

                }

 

                echo "<td>\n";

                echo "<form method='POST' action='ShowCategory.php'>\n";

                echo "<input type='hidden' name='Start' value='" . ($Start + $ByPage) . "'>\n";

                echo "<input type='hidden' name='CategoryID' value='" . $_REQUEST["CategoryID"] . "'>\n";

                echo "<input type='hidden' name='SubcategoryID' value='" . $_REQUEST["SubcategoryID"] . "'>\n";

 

 

 

                if ($Start + $ByPage < $pages * $ByPage)

                {

                        echo "<input class='sub' type='submit' value='Next >>>' name='btnNext'>";

                }

 

 

                echo "</form>\n";

                echo "</td>\n";

                echo "</tr>\n";

                echo "</table><br><br>\n";

        }

Link to comment
Share on other sites

Have a look here at this pagination tutorial.

http://www.phpfreaks.com/tutorial/basic-pagination

 

You can follow that tutorial, but that paginates all the results, would just need to add a limit at the end of your query, and then another query with no limits and see how many rows that result contains to be used for the pagination.

 

To sum it up:

$sql = "SELECT id, number FROM numbers WHERE product='product_name' LIMIT $offset,$rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$sql_count = "SELECT id, number FROM numbers WHERE product='product_name'";
$numrows = mysql_num_rows($sql_count);

 

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.