Jump to content

paging records


davids_media

Recommended Posts

I am trying to find a simple solution to page my records

 

Here is the code thus far below

 

<?php
$title = "Pick your Product";

//Set number of columns to use
$maxCols = 3;

error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors", 1);

require_once ('./includes/config.inc.php');

require_once (MYSQL);

include ('./includes/header.html');

include ('./includes/main.html');

if($id = isset($_GET['catID'])) 
{

    //Create and run query to get product category names for the selected cat ID
    $query = "SELECT `product`.`prodID`, `product`.`product`, `category`.`cat`, `product`.`prod_descr`, `category`.`cat_descr`, `product`.`price`, `product`.`image`, `product`.`stock`
              FROM `product`
              LEFT JOIN `category` ON `product`.`catID` = `category`.`catID`
              WHERE `product`.`catID`='{$_GET['catID']}'
              ORDER BY `product`.`product`";
    $r = mysqli_query($dbc, $query);

$showHeader = true;

echo "<div id='right'>";

    while($row = mysqli_fetch_array($r))
    {
        if($showHeader)
        {
		echo "<table class='table-container'>";
            //Display category header
            echo "<h1>" . "<span>" . "# " . "</span>" . $row['cat'] .  "<span>" . " #" . "</span>" . "</h1>";
		echo "<h2>" . $row['cat_descr'] . "</h2>";
            $showHeader = false;


		 //Set index var to track record count
        $recIdx = 0;

            $recIdx++;

            //Open new row if needed
            if($recIdx % $maxCols == 1)
            {
                echo "<tr>";
            }

        }

            //Display product	
            echo "<td>";
            echo "<img src='db/images/".$row['image']."' height=150px width=150px /><br>";
            echo "<li>" . "<a href='item.php?prodID={$row['prodID']}' title='{$row['product']}'>" . $row['product'] . "</a>" . "</li>";
            echo "<span>" . "£". $row['price'] . "</span>"; 

		if ($row['stock'] < 2) // If there less than two items in stock!!
		{
			echo " (<span> Low in Stock! </span>) ";
		}
		elseif ($row ['stock'] = 0)
		{
			echo "Sorry, currently not available but we will try hard to get more in!";
		}




            echo "</td>";

            //Close row if needed
            if($recIdx % $maxCols == 1)
            {
                echo "</tr>";
            }
        }

        //Close last row if needed
        if($recIdx % $maxCols == 0)
        {
            echo "</tr>";
        }

        //Close table & div
    }

        echo "</table>";
        echo "</div>";

include ('./includes/footer.html');

?>

 

Theres no pagination thus far but can I possibly embed it into the code I have please?

Link to comment
Share on other sites

The link looks good.

The only thing I'd add to it is that if you have a more complex query connected to a post form the variables don't carry over so to keep any additional search arguments (if any) you must parse the, separately either through hidden fields or through get variables in the URL.

If you do choose the later you will have to use url_encode() and url_decode() to use that information.

This might not be necessary in your case, I just mention it on the topic of pagination.

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.