megha_3000
02-09-2012, 04:43 AM
creating dynamic product list in php. i.e. customer can see all products from list and select the products.i have created a list from where customer can see the newest 6 products. but its also necessary in list that they can view all the products and select as much item as necessary from list and add them to cart. my code is given below:
<?php
// Run a select query to get latest 6 items
//connect to database
include ("db.php");
$dynamicList="";
$sql = mysql_query ("SELECT * FROM products ORDER BY date_added DESC limit 6");
$productCount= mysql_num_rows($sql);//count 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" cellpadding="6" cellspacing="0"><tr><td width="17%" valign="top"><a href="product.php?id='.$id.'"><img style="border:#666 ipx 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 /> TK'.$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();//closes an available open connection found by php
?>
how can i make it more acceptable, more reliable and more dynamic??
<?php
// Run a select query to get latest 6 items
//connect to database
include ("db.php");
$dynamicList="";
$sql = mysql_query ("SELECT * FROM products ORDER BY date_added DESC limit 6");
$productCount= mysql_num_rows($sql);//count 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" cellpadding="6" cellspacing="0"><tr><td width="17%" valign="top"><a href="product.php?id='.$id.'"><img style="border:#666 ipx 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 /> TK'.$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();//closes an available open connection found by php
?>
how can i make it more acceptable, more reliable and more dynamic??