<?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 列のテーブルから 1 つのテーブル セルに表示し、追加の行を動的に追加します。
これは、表示されるはずの場所の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'];
}
?>