0
<?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'];
}
?>
4

2 回答 2

0

不要使用 exit(); 它停止脚本。所以它从不“回声”,甚至“没有该类别的产品”。

如果包含第一个代码,请使用 return;而不是退出()。但我看不到你在哪里插入了哪些代码。

于 2012-07-18T10:54:02.697 回答
0

您必须使用category LIKE '%red%'来匹配诸如“red medium Christmas”和“alsored category”等类别。category LIKE 'red'仅匹配“红色”类别。

请参阅http://www.techonthenet.com/sql/like.php了解更多关于LIKE.

于 2012-07-18T12:03:59.060 回答