/    Sign up×
Community /Pin to ProfileBookmark

Generating Product List Pages

I have the general layout of my store setup up but I need help generating the product list pages. THere will be 6 items on each page but how do I generate these pages? The items will be in a database by category. For example when someone clicks a link on the left navigation what will the name of that page be? I know I could just reload the page with different items but then there would only be an index page. So my question is how do I generate pages and also individual item pages when “view detail” button is pressed that will work with SEO standards(URL’s with meaning full names?). Thanks

Link:[URL=”http://www.cs.scranton.edu/~eaganr2/sjm2/index.php”]http://www.cs.scranton.edu/~eaganr2/sjm2/index.php[/URL]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@tirnaMar 30.2010 — This is just an overall structure of a typical online store that I build.

1) Somewhere on a categories page you will have a list of links, select list or whatever from which the user can select a category to display its items.

2) When the user selects a category, you run a single script (say called displayProducts.php) and send to it the category_id for the category the user selected.

3) displayProducts.php then displays the products for the inputed category_id.

If the number of products in the selected category exceeds the number you want to display per page then you can use this template pagination script as your displayProducts.php and modify it accordingly to display the products in a category with your selected products per page.

[code=php]
<?php
session_start();
/********************************************************
This is a standalone demo pagination script.
Change the db connect settings $query to suit your own test database
**********************************************************/
//----------------------------------------------------------------------------------------------------------------------
//connect to the database
$DB_USERNAME = "root"; //database user account name
$DB_PASSWORD = ""; //database user account password
$DB_NAME = "test"; //name of database
$DB_HOST = "localhost"; //name of host
$newlink = true;

$conn = mysql_connect($DB_HOST,$DB_USERNAME,$DB_PASSWORD,$newlink) or die('<br />1-Cannot connect to the database at the moment.<br /><br />Please try again later.<br />'); //connect to mysql

$isDbSelected = mysql_select_db($DB_NAME, $conn) or die('<br />2-Cannot connect to the database at the moment.<br /><br />Please try again later.<br />'); //connect to the db
//----------------------------------------------------------------------------------------------------------------------
$linesPerPage = 3; //number of lines to print per page
//check if a page link was clicked
if(isset($_GET['txtPgNum']))
{
$_SESSION['currPage'] = $_GET['txtPgNum']; //txtPgNum comes from the page links
unset($_GET['txtPgNum']);
}
//check if either 'previous' or 'next' buttons were clicked
else if(isset($_GET['dir']))
{
$direction = $_GET['dir']; // -1 = prev page 1 = next page
unset($_GET['dir']);

$_SESSION['currPage'] = $_SESSION['currPage'] + $direction;
if($_SESSION['currPage'] < 1) $_SESSION['currPage'] = 1;
if($_SESSION['currPage'] > $_SESSION['totPages']) $_SESSION['currPage'] = $_SESSION['totPages'];

}
else //neither a page link or previous or next buttons were clicked. This must then be the first call to this page
{
$_SESSION['currPage'] = 1; //set current page = 1

//select all the records to work out max number of rows and number of pages needed
$query = 'select * from tblperson';
$rs = mysql_query($query,$conn) or die("<p>3-Server is busy.<br />Please try again later.</p>");
$totRows = mysql_num_rows($rs); //total number of rows to display
if($totRows&#37;$linesPerPage == 0)
$totPages = $totRows/$linesPerPage;
else
$totPages = round(($totRows/$linesPerPage)+0.5); //total number of pages required

mysql_free_result($rs);

$_SESSION['totRows'] = $totRows;
$_SESSION['totPages'] = $totPages;
}

//calculate the first record number to retrieve from the DB for this page
$_SESSION['offset'] = ($_SESSION['currPage']*$linesPerPage)-$linesPerPage;

if($_SESSION['offset'] < 0) $_SESSION['offset'] = 0;
if($_SESSION['offset'] > $_SESSION['totRows']) $_SESSION['offset'] = $_SESSION['totRows'];
/* Debugging code block
echo 'total rows = '.$_SESSION['totRows'].'<br />';
echo 'total pages = '.$_SESSION['totPages'].'<br />';
echo 'curr page = '.$_SESSION['currPage'].'<br />';
echo 'lines per page = '.$linesPerPage.'<br />';
echo 'offset = '.$_SESSION['offset'].'<br /><br />';
*/
//-------------------------------------------------------------------------------------------------------------------
//Code to retrieve the rows to display on the current page
$query = 'select * from tblperson limit '.$_SESSION['offset'].','.$linesPerPage;
$rs = mysql_query($query,$conn) or die("<p>3-Server is busy.<br />Please try again later.</p>");
//-------------------------------------------------------------------------------------------------------------------
?>
<html>
<head>
<title>Pagination Example</title>
<style type="text/css">
<!--
body {
font-size: 10pt;
font-family: tahoma, arial, sans serif}
#page-links-container {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px}
#page-links-container ul {
list-style-type: none}
#page-links-container ul li {
display: inline;
color: rgb(0,0,205);
padding: 3px 4px 3px 4px;
margin: 0px 0px 0px 6px}
#page-links-container ul li a {
text-decoration: none;
font-size: 10pt}
#page-links-container ul li a:hover {
text-decoration: underline}
#page-links-container ul li a:visited {
color: rgb(0,0,205);}
-->
</style>

</head>
<body>
<!-- Start of page links container -->
<div id="page-links-container">
<ul id="page-links">
<li id="liPrevPage"><a href="pagination.php?dir=-1" title="Click to view previous page">Previous</a></li>
<?php

//echo '<br />i = '.$totPages.'<br />';

for($i=1; $i<=$_SESSION['totPages']; $i=$i+1)
{
echo '<li id="liPg'.$i.'"><a href="pagination.php?txtPgNum='.$i.'" title="Go to page '.$i.'">'.$i.'</a></li>';
}
?>
<li id="liNextPage"><a href="pagination.php?dir=1" title="Click to view next page">Next</a></li>
</ul>
</div>

<!-- end of page-links-container div -->
<!-- Code block to display the DB data from row $_SESSION['offset'] to row $_SESSION['offset']+$linesPerPage -->
<table>
<?php
while($row=mysql_fetch_assoc($rs))
{
echo '<tr><td>'.$row['id'].'</td><td>'.$row['fldGivenName'].'</td><td>'.$row['fldFamilyName'].'</td></tr>';
}
mysql_free_result($rs);
mysql_close($conn);
?>
</table>
<!-- End of code block to display the DB data from row $_SESSION['offset'] to row $_SESSION['offset']+$linesPerPage -->
<?php
//hide or display the 'previous' and 'next' buttons as required
if($_SESSION['totPages'] == 1)
echo '<script type="text/javascript">document.getElementById("page-links-container").style.display="none";</script>';
if($_SESSION['currPage'] == 1)
echo '<script type="text/javascript">document.getElementById("liPrevPage").style.visibility="hidden";</script>';
else
echo '<script type="text/javascript">document.getElementById("liPrevPage").style.visibility="visible";</script>';

if($_SESSION['currPage'] == $_SESSION['totPages'])
echo '<script type="text/javascript">document.getElementById("liNextPage").style.visibility="hidden";</script>';
else
echo '<script type="text/javascript">document.getElementById("liNextPage").style.visibility="visible";</script>';

//highlight the current page's page link
echo '<script type="text/javascript">document.getElementById("liPg'.$_SESSION['currPage'].'").style.backgroundColor="rgb(200,200,200)";</script>';
echo '<script type="text/javascript">document.getElementById("liPg'.$_SESSION['currPage'].'").style.border="1px solid rgb(0,0,0)";</script>';
?>
</body>
</html>

[/code]


4) For each product displayed in displayProducts.php the script could generate code to display a link, button etc for the user to click to view the product's details. When this link/button is clicked the product_id of that product is sent to a php script (say displayProductDetails.php) which displays the details extracted from the db for that product in a pop window, a new web page, a div on the same page if using AJAX or whatever you like.

I hope the above makes sense and is a help in some way.
Copy linkTweet thisAlerts:
@Rob4226authorMar 30.2010 — Ok, I understand what you saying(btw I am not using any JavaScript for this). So basically everything is going through the displayProduct.php file, how will this affect my SEO? I'm talking in terms of what the URL will look like and also if the robots can even get to and read the product pages. Thanks.
Copy linkTweet thisAlerts:
@tirnaMar 30.2010 — To be honest, I am not an SEO expert ?.

Hopefully an SEO guru will be able to help more on that side of things.
×

Success!

Help @Rob4226 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...