I am producing an online catalog with no shopping cart for a client. Every sample I find to emulate either puts every record in its own row or fills one row with everything. My current page has the latter and prints everything in the table. I understand the current coding, but I need something slightly different.
I am looking to make a page of 10 select items (by newArrival = "Yes"), 5 items per column, 2 rows per page, with "Top", "Prev", "Next", and "Bottom" page selectors that actually work (currently mine do).
My products table consists of:
prID mediumint(4) not null auto_increment primary key
productID varchar(10) not null default "0"
productName varchar(75) not null
productImage varchar(25) not null
categoryID mediumint(4) not null default "0" (corresponds to my category table information)
newArrival enum('Yes','No') default "Yes"
My page code is:
Code:
<p style="background-color: #666666; color: #FFFFFF; font-size: 16px; padding: 7px;">New Arrivals</p>
<?php
// filename on this line
// common information include file on this line
global $records_per_page, $cur_page;
global $PHP_SELF;
$link_id = db_connect($default_dbname);
if(!$link_id) error_message(sql_error());
$query = "SELECT count(*) FROM $products_tablename";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$query_data = mysql_fetch_row($result);
$total_num_products = $query_data[0];
if(!$total_num_products) error_message('No records found!');
$page_num = $cur_page + 1;
$total_num_page = $last_page_num
= ceil($total_num_products/$records_per_page);
echo "<p align='center'>$total_num_products products found. Displaying the page $page_num out of $last_page_num.</p>\n";
if(empty($cur_page)) {
$cur_page = 0;
}
$limit_str = "LIMIT ". $cur_page * $records_per_page .
", $records_per_page";
$result = mysql_query("SELECT * FROM " . $products_tablename, $link_id);
if(!$result) error_message(sql_error());
?>
<center>
<table width="75%" border="0" cellpadding="3" cellspacing="0">
<?php
echo "<tr>\n";
while($query_data = mysql_fetch_array($result)) {
$counter = $counter + 1;
$productImage = $query_data["productImage"];
$productID = $query_data["productID"];
$productName = $query_data["productName"];
echo "<td width='20%' align='center' valign='top'><img src='./images/sample/",$productImage,"'><br /><b>",$productID,"</b><br />",$productName,"</td>\n";
}
echo "</tr>\n";
?>
</table>
<?php
if($page_num > 1) {
$prev_page = $cur_page - 1;
echo "<a href=\"$PHP_SELF?action=list_records&
sort_order=$org_sort_order&
order_by=$order_by&cur_page=0\">[Top]</a> ";
echo "<a href=\"$PHP_SELF?action=list_records&
sort_order=$org_sort_order&
order_by=$order_by&
cur_page=$prev_page\">[Prev]</a>";
}
if($page_num < $total_num_page) {
$next_page = $cur_page + 1;
$last_page = $total_num_page - 1;
echo "<a href=\"$PHP_SELF?action=list_records&
sort_order=$org_sort_order&
order_by=$order_by&
cur_page=$next_page\">[Next]</a> ";
echo "<a href=\"$PHP_SELF?action=list_records&
sort_order=$org_sort_order&
order_by=$order_by&
cur_page=$last_page\">[Bottom]</a>";
}
?>
</center>
I am trying to produce a working sample for my client by the end of the month. Any help would be appreciated. Thanks, and have a great day! :D
HollyAnn
aka Scottiegirl
"I was put on Earth to accomplish a certain number of things. Right now I am so far behind, I will never die." - Calvin, Calvin and Hobbs