3 Replies - 1335 Views - Last Post: 25 November 2012 - 08:33 AM Rate Topic: -----

#1 ranjennaidu13  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 8
  • Joined: 10-October 12

How to display specific product from the table

Posted 24 November 2012 - 08:02 AM

<?php 
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php 
// Run a select query to get all items
// Connect to the MySQL database  
include "storescripts/connect_to_mysql.php"; 
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC ");
$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"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a></td>
          <td width="83%" valign="top">' . $product_name . '<br />
            $' . $price . '<br />
            <a href="product.php?id=' . $id . '">View Product Details</a></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>Products</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">
  <?php echo $dynamicList; ?>
  </div>
  <?php include_once("template_footer.php");?>
</div>
</body>
</html>


For the coding above i can display all the products from the PRODUCTS TABLE. How i must change to just display the selected product from specific category column & subcategory column of my table. The database table screenshot as below

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: How to display specific product from the table

#2 Rpgmaster  Icon User is offline

  • New D.I.C Head

Reputation: -8
  • View blog
  • Posts: 12
  • Joined: 22-November 12

Re: How to display specific product from the table

Posted 24 November 2012 - 09:01 AM

<?php 
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php 
// Run a select query to get all items
// Connect to the MySQL database  
include "connect.php"; 
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC ");
$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"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a></td>
          <td width="83%" valign="top">' . $product_name . '<br />
            $' . $price . '<br />
            <a href="product.php?id=' . $id . '">View Product Details</a></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>Products</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">
  <?php echo $dynamicList; ?>
  </div>
  <?php include_once("template_footer.php");?>
</div>
</body>
</html>


For the coding above i can display all the products from the PRODUCTS TABLE. How i must change to just display the selected product from specific category column & subcategory column of my table. The database table screenshot as below
[/quote]
Was This Post Helpful? -2
  • +
  • -

#3 ranjennaidu13  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 8
  • Joined: 10-October 12

Re: How to display specific product from the table

Posted 25 November 2012 - 08:12 AM

rpgmaster pls provide a serious solution ..u just copy n paste the coding i provided .
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6062
  • View blog
  • Posts: 23,513
  • Joined: 23-August 08

Re: How to display specific product from the table

Posted 25 November 2012 - 08:33 AM

I have a serious solution: LEARN PHP AND MYSQL!!! All you are doing is copying and pasting crap without giving it the slightest bit of thought.
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1