【发布时间】:2015-07-04 19:50:39
【问题描述】:
我在数据库中有 3 个表,我想用“品牌和类别”表中的值填充两个下拉菜单,以便用户可以选择类别和品牌,然后生成搜索或显示页面他们从产品表中选择的依据
我是 php 的新手,但有一个 MySQL 数据库,我可以添加/编辑/删除并从中生成结果,但不确定如何执行上述操作..
我有 3 张桌子
-
品牌:
brand_id brand_title -
分类:
cat_id cat_title -
产品:
product_id product_cat product_brand product_price product_keywords
我的 php 代码在这里: 此代码从 2 下拉列表中的品牌和类别表中获取数据。 现在我想按关键字搜索,并通过从品牌和类别表中选择的选项显示产品表中的数据。 请看一下这个链接: http://ruqayyahfashion.com/product/1.php
<?Php
mysql_connect("localhost", "root", "") or die("Connection Failed");
mysql_select_db("ecomerce")or die("Connection Failed");
$sql="SELECT cat_id, cat_title FROM categories";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result))
{
$cat_id=$row["cat_id"];
$cat_title=$row["cat_title"];
$options.="<OPTION VALUE=\"$cat_id\">".$cat_title;
}
$sql1="SELECT brand_id, brand_title FROM brands";
$result1=mysql_query($sql1);
$options1="";
while ($row1=mysql_fetch_array($result1))
{
$brand_id=$row1["brand_id"];
$brand_title=$row1["brand_title"];
$options1.="<OPTION VALUE=\"$brand_id\">".$brand_title;
}
?>
<form >
<input type="text" class="form-control" placeholder="Search a Product">
<SELECT NAME=Categories>
<OPTION VALUE=0>Select a Category
<?=$options?>
</SELECT>
<SELECT NAME=Brands>
<OPTION VALUE=0>Select a Brand
<?=$options1?>
</SELECT>
<button type="submit" name="btn">Search</button>
</form>
【问题讨论】: