我正在创建一个搜索表单,该表单使用多个表单从包含肉类包装信息的数据库中获取匹配结果。我最终希望用户能够使用表单来搜索包裹的宽度、长度、类型、形状和描述。仅显示匹配结果。
目前我有 3 个下拉框,所有的工作都可以找到匹配的结果。不幸的是,它们似乎完全覆盖了其他表单术语(另一个问题),但我想添加一个“任何”功能,这样用户就可以搜索任何内容,而不必每次都对所有下拉框进行特定搜索,从而限制结果的数量那将会出现。
HTML 代码:
<body>
<form action="form3.php" method="post">
<label for ="toolcode">Toolcode: </label>
<input type="text" name="term" /><br />
<label for ="delyncode">Delyn code: </label>
<input type="text" name="term" /><br />
<label for ="description">Description: </label>
<input type="text" name="term" /><br />
<label for ="traysize">Traysize: </label>
<input type="text" name="term" /> <br />
<label for ="trayheight">Trayheight: </label>
<input type="text" name="term" /> <br />
<label for ="traywidth">Traywidth: </label>
<input type="text" name="term" /> <br />
<label for ="traydepth">Traydepth: </label>
<input type="text" name="term" /> <br />
<label for="trayrange">Trayrange: </label>
<select name="trayrange">
<option value="Other">--Any--</option>
<option value="BBQ">BBQ</option>
<option value="Dessert">Dessert</option>
<option value="Display">Display</option>
<option value="Meat">Meat</option>
<option value="Microwave">Microwave</option>
<option value="Party">Party</option>
<option value="Salad/Wet Pasta">Salad/Wet Pasta</option>
<option value="Snacks">Snacks</option>
<option value="Standard">Standard</option>
</select>
<label for ="traytype">Traytype: </label>
<select name="traytype">
<option value="Other">--Any--</option>
<option value="Open">Open</option>
<option value="Cavitised">Cavitised</option>
<option value="Lid">Lid</option>
<option value="Tray">Tray</option>
<option value="Coallition">Coallition</option>
<option value="Bowl">Bowl</option>
<option value="Hinge pack">Open</option>
<option value="Pot">Pot</option>
<option value="Base & Lid">Base and Lid</option>
<option value="Rectangular">Rectangular</option>
<option value="Specalist">Specialist</option>
</select><br />
<label for="trayshape">Trayshape: </label>
<select name="trayshape">
<option value="Other">--Any--</option>
<option value="Rectangular">Rectangular</option>
<option value="Oval">Oval</option>
<option value="Square">Square</option>
<option value="Insert">Insert</option>
<option value="Round">Round</option>
<option value="Open">Open</option>
</select><br />
<input type="submit" value="Submit" />
</form>
</body>
我上面的当前“任何”选项只是一个测试。它不起作用,没有结果显示。
PHP代码:
<body>
<?php
$con = mysql_connect ("localhost", "root", "");
mysql_select_db ("delyn_db", $con);
if (!$con)
{
die ("Could not connect: " . mysql_error());
}
$varRange = $_POST['trayrange'];
$varType = $_POST['traytype'];
$varShape = $_POST['trayshape'];
$term = mysql_real_escape_string($_POST['term']);
$sql = "SELECT * FROM delyn WHERE toolcode LIKE '%".$term."%' AND delyncode LIKE
'%".$term."%' AND description LIKE '%".$term."%' AND traysize LIKE
'%".$term."%' AND trayheight LIKE '%".$term."%' AND traywidth LIKE
'%".$term."%' AND traydepth LIKE '%".$term."%' AND trayrange LIKE
'%".$varRange."%' AND traytype LIKE '%".$varType."%' AND trayshape LIKE
'%".$varShape."%' ";
$r_query = mysql_query($sql);
while ($row = mysql_fetch_array($r_query))
{
echo '<br /> Delyn code: ' .$row['delyncode'];
echo '<br /> Tool Code: '.$row['toolcode'];
echo '<br /> Description: '.$row['description'];
echo '<br /> Tray range '.$row['trayrange'];
echo '<br /> Tray type: '.$row['traytype'];
echo '<br /> Tray size: '.$row['traysize'];
echo '<br /> Tray height: '.$row['trayheight'];
echo '<br /> Tray width: '.$row['traywidth'];
echo '<br /> Tray depth: '.$row['traydepth'];
echo '<br /> Tray shape: '.$row['trayshape'] . '<br />' . '<br />'; ;
}
?>
</body>
我需要添加什么以允许用户搜索允许任何“托盘范围”、“托盘形状”和“托盘类型”。这在理论上应该显示与输入了信息的表单相匹配的结果。
提前感谢任何可以提供帮助的人。