<?php
$product_list="";
if(isset($_GET['cat'])){
$sql = mysql_query("SELECT*FROM products WHERE category LIKE'$category'");
while($row=mysql_fetch_array($sql)){
$tablerow='3';
$product_list.='<tr>';
while($tablerow >= 0){
$id=$row["id"];
$name=$row["name"];
$price=$row["price"];
$date_added = strftime("%b %d, 20%y",strtotime($row["date_added"]));
$discriptiontags = $row['category'];
$discription = $row['subcategory'];
$size = $row['details'];
$qty= $row['inv'];
$product_list.='<td><img src="inventory_images/'.$id.'.jpg" width="250" height="167"/><br/>$name</td>';
$tablerow=$tablerow-1;
}
$product_list.='</tr>';
}
}else{
$product_list = "no products in this category";
exit();
}
?>
所以这背后的想法是;使用 $_GET 为我的数据库获取类别标签,并使用 LIKE 查找行信息并在一个表单元格中显示每行信息,该表来自一个跨 3 列的表,并动态添加其他行。
这是应该显示的地方的html
<table width="760px" border="1" cellpadding="4">
<?php echo $product_list ?>
</table>
我选择绿色类别进行测试,因为它有 3 个项目。
也由于某种原因,如果未设置 url 变量,则页面根本不显示...????
页面上的其余 php:
<?php
///conect to mysql
///grab page variable
include "storescript/connect_to_mysql.php";
$category="";
$tab="-1";
if(isset($_GET['cat'])){
$category=$_GET['cat'];
}
if(isset($_GET['tab'])){
$tab=$_GET['tab'];
}
?>