Thread: Storing prices
View Single Post
Old 11-09-2012, 11:11 AM   PM User | #34
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 849
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
My plan is when they click on a link product link, I want to show a heading underneath say "PET HOUSING" with a brief description of bird houses in general, maybe going into a little detail about the timber used etc. Then I want to display all the product images relating to that product, and that's it. When they click another product, it changes the content to that product.

I'm currently having issues with my query.

This is my set up:
PHP Code:
<?php 

if (isset($_GET['page']) && $_GET['page'] == "products") {

   if (isset(
$_GET['order'])){
      
      switch (
$_GET['order']) {
         case 
'Bench':
            require(
"core/get_products.php");
         break;
         
         case 
'Bin Stores':
         
         break;
      }
      
   }
   else{
      echo 
"display all products";
   }
}




include(
"core/init.inc.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>
<title><?php echo "Gardenable - ".$title?></title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="js/clock.js"></script>
</head>

<body>
<div id="container">

   <div id="header">
      <img src="images/gardenable2.fw.png" alt="Gardenable Logo" title="Gardenable" id="logo" border="0" />
      
      <div id="navigation_div">
         <img src="images/flowerbed.fw.png" alt="Navigation Image" id="flowerbed_img" border="0" />
         <ul>
             <li><a href="?page=home">Home</a></li>
             <li><a href="?page=about">About</a></li>
             <li><a href="?page=products">Products</a></li>
             <li><a href="?page=contact">Contact</a></li>
             <li><a href="?page=find">Find Us</a></li>
         </ul>
      </div>
   </div>
   
   <div id="content">
     
     <?php include($include_page); ?>
   
   </div>
   
   
   
   <div id="footer">
   
   
   </div>
   
</div>
<p id="pageviews"><?php echo "Page Hits: ".$page_views?></p>
</body>
</html>
At the very top of this file I include a script init.inc.php which determines which content to generate (for the separate pages of the site). When I click on the product link, it generates a file called product_template.htm, which is here:

Code:
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. 
   The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, 
   content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as 
   their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy.</p>
   
<div id="products_wrapper">
    <div id="product_menu_div">
	    <ul>
		   <li><a href="?page=products&order=Bench">Benches</a></li>
		   <li><a href="?page=products&order=Bin Stores">Bin Stores</a></li>
		   <li><a href="?page=products&order=Bird Housing"><li>Bird Housing</a></li>
		   <li><a href="?page=products&order=Decking"><li>Decking</a></li>
		   <li><a href="?page=products&order=Fence"><li>Fencing</a></li>
		   <li><a href="?page=products&order=Gates"><li>Gates</a></li>
		   <li><a href="?page=products&order=Pet Housing"><li>Pet Housing</a></li>
		   <li><a href="?page=products&order=Planters"><li>Planters</a></li>
		   <li><a href="?page=products&order=Sheds"><li>Sheds</a></li>
		   <li><a href="?page=products&order=Table"><li>Tables</a></li>
		</ul>
	</div>
	
	
	
</div>
This is loaded in as a template. As you can see, I click on a product link which passes 2 values back to index.php. At the very top of index.php, I also have this bit of code (to determine if there were 2 variables passed in):

PHP Code:
if (isset($_GET['page']) && $_GET['page'] == "products") {

   if (isset(
$_GET['order'])){
      
      switch (
$_GET['order']) {
         case 
'Bench':
            require(
"core/get_products.php");
         break;
         
         case 
'Bin Stores':
         
         break;
      }
      
   }
   else{
      echo 
"display all products";
   }

If/else and Switch working fine. As you can see from the switch, I require another file (get_products.php) which is where I am going to query the database. Here is that file:
PHP Code:
<?php

//connect to server, select db, query table.
$connection mysql_connect("localhost","root","") or die("Error connecting to server.");
$database mysql_select_db("gardenable",$connection) or die("Error selecting the database.");
$query mysql_query("SELECT P.*, I.imgName FROM products AS P, product_images AS I WHERE P.productID = I.productID AND P.product_name = {$_GET['order']}") or die("error selecting records");

echo 
"<pre>";
print_r(mysql_fetch_array($query));
echo 
"</pre>";

//setup variables ready to be used with the database data.
$count 0;//used to iterate through $product_array to store results.
$product_array = array();//array to store database data.

$full_dir dirname(__FILE__);
$dir_files scandir($full_dir);
$image_directory "core/".$dir_files[6]."/";

while (
$row mysql_fetch_array($query)) {
      
      
$product_array[$count] = array(
                       
"productID" => $row['productID'],
                       
"productName" => $row['product_name'],
                       
"productDetails" => $row['product_details'],
                       
"productPrice" => "&pound;".$row['product_price']
                    );
      
$count++;
}

?>
Ignore anything after the query, that needs to be changed a little I think and also my code doesn't reach that far!

The query line keeps executing the die() part. Not sure what is wrong with it. I know that P.product_name needs to match the value which we pass in so it knows which images to select. I have echo'd out the $_GET['order'] value inside my get_products.php page so it can't be that.

I'm really stumped, would appreciate if you could help me further.

Kind regards,

LC.
LearningCoder is offline   Reply With Quote