Displaying product categories - php

I'm creating a simple website for a business to display their products. On the index page I display the 3 newest products. What I need to do now is have a category page people can go to to view products in a certain category. I tried adapting the code from my index page but the products aren't showing up on my category.php.
I have a product_list.php with the different categories, when one is selected I'm trying to load category.php with the products from the category that was selected.
What I have:
product_list.php
<?php
include "storescripts/connect_to_mysql.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
</style>
<meta name="Description" content="Lightweight aluminum boat docks, lifts, and accessories" />
<meta name="Keywords" content="Aluminum boat dock ladder lift water wheels" />
<script src="scripts/swfobject_modified.js" type="text/javascript"></script>
</head>
<title><?php echo $product_name; ?></title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen"/>
</style>
<body>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<table width="100%" border="0" cellspacing="0" cellpadding="15">
<tr>
<td valign="top" align="center"><table width="100%" border="1">
<tr>
<td align="center"><p>Aluminum Docks</p>
<p><img src="inventory_images/aluminum docks/PN99002-6_24x4_PKG_LG.jpg" width="100" height="64" alt="24X4" /></p></td> // There's a field in my DB called categories, and 'docks' is the value assigned to the products
<td align="center"><p>Floating Docks</p>
<p><img src="inventory_images/floating dock/100225279.jpg" width="100" height="60" alt="Floating Dock" /></p></td>
<td align="center"><p>Frame Docks</p>
<p><img src="inventory_images/frame dock/frameDock.jpg" width="100" height="64" alt="Frame Dock" /></p></td>
<td align="center"><p>Pipe Docks</p>
<p><img src="inventory_images/pipe dock/PN99002_16X4_SECTION_LG.jpg" width="100" height="64" alt="Pipe Dock" /></p></td>
</tr>
<tr>
<td align="center"><p>Boat Lifts</p>
<p><img src="inventory_images/boat lifts/GM1060_LG.jpg" width="100" height="64" alt="Boat Lift" /></p></td>
<td align="center"><p>Boat Lift Accessories</p>
<p><img src="inventory_images/boat lift acceessories/canopy_lg (1).png" width="100" height="64" alt="Boat Lift Accessory" /></p></td>
<td align="center"><p>Rollers & Caddies</p>
<p><img src="inventory_images/rollers and caddies/caddy270 (1).jpg" width="100" height="64" alt="Caddy" /></p></td>
<td align="center"><p>Accessories</p>
<p><img src="inventory_images/accessorries/2step_LG.png" width="100" height="64" alt="Accessory" /></p></td>
</tr>
</table>
</table>
<p> </p>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>
in category.php I'm trying to create a variable called $dynamicList with all the products that have "dock" as a category. But when I echo out $dynamicList nothing is rendered.
<?php
// Run a select query to get my letest 6 items
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
$category=$_GET['category'];
$sql = mysql_query("SELECT * FROM products WHERE category='$category' LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="17%" valign="top"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="100" height="64" border="1" /></td>
<td width="83%" valign="top">' . $product_name . '<br />
$' . $price . '<br />
View Product Details</td>
</tr>
</table>';
}
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
</style>
<meta name="Description" content="Lightweight aluminum boat docks, lifts, and accessories" />
<meta name="Keywords" content="Aluminum boat dock ladder lift water wheels" />
<script src="scripts/swfobject_modified.js" type="text/javascript"></script>
</head>
<title><?php echo $category; ?></title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen"/>
</style>
<body>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<table width="100%">
<tr>
<td valign="top"><p><?php echo $dynamicList;?><br />
</p>
<p> </p>
<p> </p> <h2> </h2></td>
</tr>
</table>
<p> </p>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>

EDIT: $dynamicList is nested in a condition statement. Just write
$dynamicList = '';
before your query
What is the current output on the page? Are the # of rows returned in the query = 0?
You should also sanitize your $category input using mysql_real_escape_string()
WHERE category ='".mysql_real_escape_string($category)."' ...

You must sanitize first the strings using this function:
public static function real_escape($string)
{
if (null != $string) {
$string = (get_magic_quotes_gpc()) ? $string : addslashes($string);
return mysql_real_escape_string($string);
}
return $string;
}
Or better use third party script like phpDataMapper

$sql = mysql_query("SELECT * FROM products WHERE category='$category' LIMIT 6");
should be
$sql = mysql_query("SELECT * FROM products WHERE category='".$category."' LIMIT 6");
This is the only error I can discover for now

Related

Inserting mysql data into a div

Trying to complete a tutorial and am trying to retrofit the styling.
I know the whole sheet of code may be anything from current,
but its helping me break down the parts and understand the whole.
That said, I am trying to insert the mysql data into divs instead of a table.
(for the thought of more responsive CSS design possibilities)
Any help would be awesome.
<?php
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
// Run a select query to get my letest 4 items
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 4");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="17%" valign="top"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></td>
<td width="83%" valign="top">' . $product_name . '<br />
$' . $price . '<br />
View Product Details</td>
</tr>
</table>';
}
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The Shop</title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
</head>
<body>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<div id="pageContent">
<table width="85%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="14%" valign="top"><h3></h3>
<p><br />
<br />
</p></td>
<td width="66%" align="center">
<h3>The Shop </h3>
<p><?php echo $dynamicList; ?><br />
</p>
<p><br />
</p></td>
<td width="20%" valign="top"><h3></h3>
<p></p></td>
</tr>
</table>
</div>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>
I'm assuming this should get you headed in the right direction (Ignore the ... accordingly)
<?php
...
$dynamicList .= '
<div>
<img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" />
</div>
<div>' . $product_name . '<br />
$' . $price . '<br />
View Product Details
</div>';
...
?>
...
<div id="pageContent">
<h3>The Shop </h3>
<?php echo $dynamicList; ?>
</div>

Links to web pages that are php includes goes back to home page

I don't profess to be any good at php, so those who are expert please don't bash me for my noob approach. I am trying to learn.
Some time back, I had someone show me how to break up parts of my web pages and write them as includes so that I wasn't having headers, footers, and navigation repainting for every page. As of yesterday morning, my pages were loading fine, and have been for many years now. However, something seems to have gone wrong, possibly on my server, and now all pages go to home page.
I have my pages set up as such:
index.php
<?php
if (! isset($HTTP_GET_VARS['content']) || ! $HTTP_GET_VARS['content']){
$content="squeeze";
}
else
$content=$HTTP_GET_VARS['content'];
//1
if ($content == "do-you-have-success-habits"){
$page_title="Do You Have Success Habits?";
$keywords="Booking Agent Book, Music Business Career Development Information, Performing Arts Entertainment Information";
$desc="Music Business Booking Management artist career development for musicians, performing artists, agents and managers";
$style="../scripts/style.css";
$popupjs="none";
$storbutnjs="none";
$retreatjs="none";
$rolloverjs="none";
$readform_chkjs="none";
$logo="req-files/logo.html";
$navbar="req-files/navbar.html";
$sidebar="req-files/sidebar.html";
$main="weekly/2013/do-you-have-success-habits.html";
}
include ("req-files/head.html");
include ($logo);
include ($navbar);
include ($sidebar);
include ($main);
include ("req-files/footer.html");
?>
This is a chopped down version of what I have. The whole index.php has all pages written like this, but it also contains includes to other php pages. There is so much content to this site that I've had to build php pages with like informations within one page... I.E. all affiliates would go into affiliates.php and then included into my index.php as such.
// INCLUDE AFFILIATES HERE
include ("affiliates.php");
I'm hoping this is enough information to help me troubleshoot my problem.
A sample of my pieces are like this header file. My variables are in the pieces.
head.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php print $page_title ?></title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="author" content=" " />
<meta name="keywords" content="<?php print $keywords ?>" />
<meta name="description" content="<?php print $desc ?>" />
<meta name="copyright" content="2006-2013" />
<link rel="stylesheet" type="text/css" href="<?php print $style ?>" />
<link href="scripts/twoColLiqLtHdr.css" rel="stylesheet" type="text/css" /><!--[if IE]>
<style type="text/css">
/* place css fixes for all versions of IE in this conditional comment */
.twoColLiqLtHdr #sidebar1 { padding-top: 30px; }
.twoColLiqLtHdr #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
<link rel="stylesheet" type="text/css" href="scripts/style.css" />
<script src="scripts/stuHover.js" type="text/javascript"></script>
<link href="scripts/dropdown_menu.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="/favicon.png" />
<?php
if ($popupjs != "none") {
print("<script src=\"${popupjs}\">");
print("</script>\n");
}
if ($storbutnjs != "none") {
print(" <script src=\"${storbutnjs}\">");
print("</script>\n");
}
if ($retreatjs != "none") {
print(" <script src=\"${retreatjs}\">");
print("</script>\n");
}
if ($rolloverjs != "none") {
print(" <script src=\"${rolloverjs}\">");
print("</script>\n");
}
if ($readform_chkjs != "none") {
print(" <script src=\"${readform_chkjs}\">");
print("</script>\n");
}
?>
</head>
As stated before, I am inexperienced with php. So, I'm having trouble understanding why my pages linked in my nav are going to home (squeeze) page.
Now, my hosting tech support states that it could be deprecated code that is causing this to fail. They are migrating my site, probably to a previous version of php. But I need to know where to begin fixing this. I hope it is a simple fix because this site is huge!
Thank you for your patience and your help.
Heidi
#DrCord:
On this particular example I gave, there are two nav systems. One I call sidebar the other menu. Both are set up as partial html pages.
menu.html
<tr>
<td align="center"><img src="images/design_elements/yellow_spacer.gif" alt="Yellow line" width="745" height="2" border="0" /></td>
</tr>
<tr>
<td align="center" valign="middle" background="images/design_elements/navbar.jpg" width="760" height="42" class="menubar"><nobr>About</nobr> | <nobr>Articles</nobr> | <nobr>Consulting</nobr> | <nobr>Booking Tools</nobr> | <nobr>Seminars</nobr> | <nobr>Teleseminars</nobr> | <nobr>Contact</nobr> | <nobr>Media EPK</nobr> | <nobr>Links</nobr></td>
</tr>
<tr>
<td align="center"><img src="images/design_elements/yellow_spacer.gif" alt="Yellow line" width="745" height="2" border="0" /></td>
</tr>
<tr>
<td><img src="images/design_elements/spacer.gif" alt="spacer" width="1" height="10" border="0" /></td>
</tr>
</table>
sidebar.html
<div id="container2">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td background="images/design_elements/lt-side-shadow.jpg" width="40"><img src="images/design_elements/lt-side-shadow.jpg" border="0" width="40" height="10" alt="Design Element" /></td>
<td valign="top">
<div id="sidebar1">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" style="padding: 10px;">
<table width="90%" border="0" cellpadding="0" cellspacing="0" id="cont">
<tr>
<td class="head">Articles</td>
</tr>
<tr>
<td class="head">Biz Coaching</td>
</tr>
<tr>
<td class="subhead" style="padding-left:10px;" nowrap="nowrap">Programs</td>
</tr>
<tr>
<td class="subhead" style="padding-left:10px;" nowrap="nowrap">Testimonials</td>
</tr>
<tr>
<td class="head">Books</td>
</tr>
<tr>
<td class="subhead" style="padding-left:10px; font-size:95%;" nowrap="nowrap">Huge Success</td>
</tr>
<tr>
<td class="subhead" style="padding-left:10px;" nowrap="nowrap">Guide to Touring</td>
</tr>
<tr>
<td class="subhead" style="padding-left:10px;" nowrap="nowrap">E-Book</td>
</tr>
<tr>
<td class="subhead" style="padding-left:10px;" nowrap="nowrap">I Recommend</td>
</tr>
</table>
<!-- end #sidebar1 --></div>
Again, I thank you for your patience and your help. I know that I need to learn more about PHP, and I am. I am just not clear on what the actual problem is here.

iframe doesn't work in PHP? [duplicate]

This question already has an answer here:
Echo inside an element attribute?
(1 answer)
Closed 10 years ago.
I have a php file which will show a list of images/products dynamically from the mysql database! This bit works just fine.
but I am trying to but the command in the iframe so I can create a slideshow affect using iframe!
but when I put the iframe around the command it doesn't work for some reason! it will open a 404 page on my 000web hosting server!!
here is my code:
<?php
include "config/connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 10");
$i = 0;
// Establish the output variable
$dyn_table = '<table border="0" cellpadding="6">';
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
if ($i % 5 == 0) { // if $i is divisible by our target number (in this case "5")
$dyn_table .= '<tr><td><div style="position:relative" class="shadow tr" id="products_holder"><div style="position:absolute;left:-10px;top:-12px;">
<img src="images/best.png" width="97" height="94" />
</div><img style=" margin:5px; border:#ccc 1px solid" src="inventory_images/' . $id . '.jpg" width="150" height="160"/></div></td>';
} else {
$dyn_table .= '<td><div style="position:relative" class="shadow tr" id="products_holder"><div style="position:absolute;left:-10px;top:-12px;">
<img src="images/best.png" width="97" height="94" />
</div><img style=" margin:5px; border:#ccc 1px solid" src="inventory_images/' . $id . '.jpg" width="150" height="160"/></div></div></td>';
}
$i++;
}
$dyn_table .= '</tr></table>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<script src="scripts/modernizr-2.6.1.min.js"></script>
<title>site.com</title>
<style type="text/css">
</style>
</head>
<body>
<div align="center" id="wrapper">
<?php include_once("temps/header.php"); ?>
<div id="content">
<div id="apDiv1">
<h2>Top pros</h2></div>
<table width="100%" border="0" cellspacing="0" cellpadding="17">
<tr>
<td width="2%" height="20"> </td>
<td width="98%" height="20"><p><?php echo $dyn_table; ?></p>
</tr>
</table>
<table align="center" style=" table-layout:fixed; background-image:url(images/secondSection.png);" height="82" width="100%" border="0" cellspacing="10" cellpadding="10">
<tr>
<td width="2%" height="31"> </td>
<td style="vertical-align:top" align="center" width="28%"><div id="apDiv555" class="top_btns">
<h6 class="shadow"> More Products</h6>
</div></td>
<td style="vertical-align:top" align="center" width="70%"><div id="apDiv55" class="top_btns">
<h6><span class="shadow"> Search By Clothing | Search By Retailers</span></h6>
</div></td>
</tr>
</table>
<table style="background-image: url(images/tbl_bg.png); background-repeat: repeat-x;" height="350px" width="100%" border="0" cellspacing="12" cellpadding="0">
<tr>
<td width="3%"></td>
<td width="97%"><iframe src="<?php echo $dyn_table; ?>" height="250" width="100%" ></iframe></td>
</tr>
</table>
</table>
<table height="100" width="100%" border="0" cellspacing="17" cellpadding="17">
<tr>
<td> </td>
</tr>
</table>
</div>
</div>
<?php include_once ("temps/footer.php"); ?>
</body>
</html>
any help would be grately appreciated as I am almost done with this project.
Th
Just loose the iFrame and echo the $dyn_table inside the table you already have?
Your are not aware of what an iframe means, maybe :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<script src="scripts/modernizr-2.6.1.min.js"></script>
<title>site.com</title>
<style type="text/css">
</style>
</head>
<body>
<div align="center" id="wrapper">
<?php include_once("temps/header.php"); ?>
<div id="content">
<div id="apDiv1">
<h2>Top pros</h2></div>
<table width="100%" border="0" cellspacing="0" cellpadding="17">
<tr>
<td width="2%" height="20"> </td>
<td width="98%" height="20"><p><?php echo $dyn_table; ?></p>
</tr>
</table>
<table align="center" style=" table-layout:fixed; background-image:url(images/secondSection.png);" height="82" width="100%" border="0" cellspacing="10" cellpadding="10">
<tr>
<td width="2%" height="31"> </td>
<td style="vertical-align:top" align="center" width="28%"><div id="apDiv555" class="top_btns">
<h6 class="shadow"> More Products</h6>
</div></td>
<td style="vertical-align:top" align="center" width="70%"><div id="apDiv55" class="top_btns">
<h6><span class="shadow"> Search By Clothing | Search By Retailers</span></h6>
</div></td>
</tr>
</table>
<table style="background-image: url(images/tbl_bg.png); background-repeat: repeat-x;" height="350px" width="100%" border="0" cellspacing="12" cellpadding="0">
<tr>
<td width="3%"></td>
<td width="97%"><iframe src="my_iframe.php" height="250" width="100%" ></iframe></td>
</tr>
</table>
</table>
<table height="100" width="100%" border="0" cellspacing="17" cellpadding="17">
<tr>
<td> </td>
</tr>
</table>
</div>
</div>
<?php include_once ("temps/footer.php"); ?>
</body>
</html>
// Context on the my_iframe.php
<?php
include "config/connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 10");
$i = 0;
// Establish the output variable
$dyn_table = '<table border="0" cellpadding="6">';
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
if ($i % 5 == 0) { // if $i is divisible by our target number (in this case "5")
$dyn_table .= '<tr><td><div style="position:relative" class="shadow tr" id="products_holder"><div style="position:absolute;left:-10px;top:-12px;">
<img src="images/best.png" width="97" height="94" />
</div><img style=" margin:5px; border:#ccc 1px solid" src="inventory_images/' . $id . '.jpg" width="150" height="160"/></div></td>';
} else {
$dyn_table .= '<td><div style="position:relative" class="shadow tr" id="products_holder"><div style="position:absolute;left:-10px;top:-12px;">
<img src="images/best.png" width="97" height="94" />
</div><img style=" margin:5px; border:#ccc 1px solid" src="inventory_images/' . $id . '.jpg" width="150" height="160"/></div></div></td>';
}
$i++;
}
$dyn_table .= '</tr></table>';
echo $dyn_table;
?>
An iframe it's a totally different page, so you should use 2 pages....just like a propose, one for the html and one for the iframe....i hope it helps.
PS: I change the a href ;)
Saludos ;)

Show database entries after pressing submit button

I have a page where I search for the books that an author wrote (really basic search based on an assignment I had 2 months ago). I choose the author from a dropdown box and after I press the "Submit" button the results should appear.
Here is the page's code:
<?php
include ("includes/connections.php");
if($_POST)
{
if (!isset($_POST["authors"])){
header("Location: searchAuthor.php");
exit;
}
foreach ($_POST["authors"] as $author)
{
?????????
}
}
?>
<?php include ("includes/connections.php");
function dropdown($intIdField, $strfNameField, $strlNameField, $strTableName, $strOrderField, $strNameOrdinal, $strMethod="asc") {
echo "<select name=\"{$strNameOrdinal}[]\">\n";
echo "<option value=\"NULL\">Select Value</option>\n";
$strQuery = "SELECT $intIdField, $strfNameField, $strlNameField
FROM $strTableName
ORDER BY $strOrderField $strMethod";
$rsrcResult = mysql_query($strQuery) or die(mysql_error());
while($arrayRow = mysql_fetch_assoc($rsrcResult)) {
$strA = $arrayRow["$intIdField"];
$strB = $arrayRow["$strlNameField"] . " " . $arrayRow["$strfNameField"];
echo "<option value=\"$strA\">$strB</option>\n";
}
echo "</select>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add Book Information</title>
<link href="back.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Search for Books of an Author</h1><table width="528" border="0" align="center">
<tr>
<td width="480"><span id="tip">*Hitting the "Search books of Author" button without filling the fields with an asterisk will just reset the form</span></td>
</tr>
</table>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" id="formBook">
<table width="563" border="0" align="center">
<tr>
<td style="text-align: right"><label for="authors">Select an Author*:</label></td>
<td><?php dropdown("author_ID", "author_firstname", "author_lastname", "author", "author_lastname", "authors"); ?></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Search books of Author" /></td>
</tr>
<tr>
<td><div align="left"><img src="images/buttonleft.png" alt="previous" width="70" height="70" usemap="#Previous" border="0"></div></td>
<td><div align="right"><img src="images/buttonright.png" alt="next" width="70" height="70" usemap="#Next" border="0">
<map name="Previous">
<area shape="circle" coords="35,35,33" href="addSubject.php">
</map>
<map name="Next">
<area shape="circle" coords="35,35,33" href="addEdition.php">
</map>
</div></td>
</tr>
</table>
</form>
</body>
</html>
As you can see I have everything inside a table (convenient for small stuff like this). I want when I press the submit button, the author that was chosen to be inputed in a method which will display the results from the query. The query will be executed in the foreach where the ?????? are. Then I want the result of the query to be used to display inside my table (by adding more rows and inserting one result in each row through a php function) the results.
Is there a way to do that just with php? I don't know how to use Javascript just php and html. Even if I have to insert the result of the query in another page and display everything there I'm ok with that.
I haven't written the query just yet.
Actually the foreach is there to put in a single variable each book the author has written.
Here's an example. Queries/fields are bogus.
<?php
if (isset($_POST['Submit'])) {
$strQuery = "SELECT 'field1', 'field2', 'field3'
FROM $strTableName
ORDER BY $strOrderField $strMethod";
$rsrcResult = mysql_query($strQuery) or die(mysql_error());
?>
<table>
<td> HEADER 1 </td> <td> HEADER 2 </td> <td> HEADER 3 </td>
<?php
while ($row = mysql_fetch_array($rsrcResult) {
echo "<tr><td>".$row['field1']."</td><td>".$row['field2']."</td><td>".$row['field3']."</td>";
}
?>
</table>

PHP return to previous page

I've created a product catalogue with category - subcategory - individual product page. I pass a $category to the individual product page. This page lists various details about the item, including which category the item belongs to. Since the $category variable is already set, I thought Return to previous category would be enough to return it to the subcategory page but it doesn't, part of the category.php that handles this looks like this.
EDIT: Full code
product_list.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
include "storescripts/connect_to_mysql.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
</style>
<meta name="Description" content="Lightweight aluminum boat docks, lifts, and accessories" />
<meta name="Keywords" content="Aluminum boat dock ladder lift water wheels" />
<script src="scripts/swfobject_modified.js" type="text/javascript"></script>
</head>
<title>Products</title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen"/>
</style>
<body>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<table width="100%" border="0" cellspacing="0" cellpadding="15">
<tr>
<td valign="top" align="center"><table width="100%" border="0" align="center">
<tr>
<td align="center" valign="middle"><p>Aluminum Docks</p>
<p><img src="inventory_images/aluminum docks/PN99002-6_24x4_PKG_LG.jpg" width="25%" height="64"/></p></td>
<td align="center"><p>Floating Docks</p>
<p><img src="inventory_images/floating dock/100225279.jpg" width="25%" height="64"/></p></td>
<td align="center"><p>Frame Docks</p>
<p><img src="inventory_images/frame dock/frameDock.jpg" width="25%" height="64" alt="Frame Dock" /></a></p></td>
<td align="center"><p>Pipe Docks</p>
<p><img src="inventory_images/pipe dock/PN99002_16X4_SECTION_LG.jpg" width="25%" height="64" alt="Pipe Dock" /></p></td>
</tr>
<tr>
<td align="center"><p>Boat Lifts</p>
<p><img src="inventory_images/boat lifts/GM1060_LG.jpg" width="25%" height="64" alt="Boat Lift" /></p></td>
<td align="center"><p>Boat Lift Accessories</p>
<p><img src="inventory_images/boat lift acceessories/canopy_lg (1).png" width="25%" height="64" alt="Boat Lift Accessory" /></p></td>
<td align="center"><p>Rollers & Caddies</p>
<p><img src="inventory_images/rollers and caddies/caddy270 (1).jpg"width="25%" height="64" alt="Caddy" /></p></td>
<td align="center"><p>Accessories</p>
<p><img src="inventory_images/accessorries/2step_LG.png" width="25%" height="64" alt="Accessory" /></p></td>
</tr>
</table>
</table>
<p> </p>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>
**category.php**
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
// Run a select query to get my letest 6 items
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
$category=$_GET['category'];
$sql = mysql_query("SELECT * FROM products WHERE category='$category' LIMIT 50");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
$dynamicList="";
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="17%" valign="top"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="100" height="64" border="1" /></td>
<td width="83%" valign="top">' . $product_name . '<br />
$' . $price . '<br />
View Product Details</td>
</tr>
</table>';
}
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
</style>
<meta name="Description" content="Lightweight aluminum boat docks, lifts, and accessories" />
<meta name="Keywords" content="Aluminum boat dock ladder lift water wheels" />
<script src="scripts/swfobject_modified.js" type="text/javascript"></script>
</head>
<title><?php echo $category; ?></title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen"/>
</style>
<body>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<div align="left">
<p><?php echo $dynamicList;?>
</p>
<div id="target_product"></div>
<p> </p>
</div>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>
**product.php**
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
include "storescripts/connect_to_mysql.php";
session_start();
//Check to see if the URL variable is set and exists in the database
if(isset($_GET['id'])){
$id=preg_replace('#[^0-9]#i','',$_GET['id']);
// Use this variable to see if the id exists, if yesthen get the product
// details, if no then exit the script and give message why.
$sql = mysql_query("SELECT * FROM products WHERE id ='$id' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
// Get all product details
while($row = mysql_fetch_array($sql)){
$product_name = $row["product_name"];
$price = $row["price"];
$details = $row["details"];
$quantity = $row["quantity_in_stock"];
$category = $row["category"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
}
}else{
echo "That item does not exist.";
exit();
}
}else{
echo "Data to render this page is missing.";
exit();
}
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
</style>
<meta name="Description" content="Lightweight aluminum boat docks, lifts, and accessories" />
<meta name="Keywords" content="Aluminum boat dock ladder lift water wheels" />
<script src="scripts/swfobject_modified.js" type="text/javascript"></script>
</head>
<title><?php echo $product_name; ?></title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen"/>
</style>
<body>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<table width="100%" border="0" cellspacing="0" cellpadding="15">
<tr>
<td width="20%" valign="top" ><img src="inventory_images/<?php echo $id;?>.jpg" alt="<?php echo $product_name; ?>" />
<td width="80%" valign="top"> <h3><?php echo $product_name; ?></h3>
<p>$<?php echo $price; ?><br/>
<?php echo $category; ?>
<br/>
<?php echo $details; ?><br/>
<?php echo $quantity;?>
<p>Return to previous category</p>
</table>
<p> </p>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>
If you want all data that was containing your previous page, use SESSION superglobal for this purpose.

Categories