继最近的一篇文章之后。
我正在创建一个查询 SQL 数据库的搜索功能。该数据库由不同类型的肉类包装组成。我创建了 HTML 和 PHP 代码,它将仅使用一个表单和提交按钮来搜索数据库并显示结果。但是我现在想创建一个有多个表单(包括三个下拉表单)的搜索框,当用户输入尺寸时,单击下拉列表并输入 id 代码,他们可以使用一个提交按钮提交,然后将被引用由匹配所有三个组合的结果组成的页面。
谁能给我一些关于如何解决这个问题的见解?我尝试创建两个表单,它们提交到同一个 PHP 页面以获得结果,但一个似乎覆盖了另一个。
这是我目前的 HTML 和 PHP 代码:
<body>
<form action="form2.php" method="post">
Search: <input type="text" name="term" /><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());
}
$term = mysql_real_escape_string($_REQUEST['term']);
$sql = "SELECT * FROM delyn WHERE toolcode LIKE '%".$term."%' OR trayheight LIKE
'%".$term."%' OR delyncode LIKE '%".$term."%' OR description LIKE '%".$term."%'
OR trayshape LIKE '%".$term."%' OR traydepth LIKE '%".$term."%' OR traywidth
LIKE '%".$term."%'";
$r_query = mysql_query($sql);
if(!$sql)
{
echo "could not find";
}
while ($row = mysql_fetch_array($r_query)){
echo 'ID: ' .$row['ID'];
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'];
echo '<br /> imagename: '.$row['imagename'];
echo '<br /> Tray live: '.$row['traylive'] . ' <br /><br />';
}
?>
</body>
提前致谢 :)
编辑过的php:
<body>
<?php
$con = mysql_connect ("localhost", "root", "");
mysql_select_db ("delyn_db", $con);
if (!$con)
{
die ("Could not connect: " . mysql_error());
}
if(isset($_POST['formSubmit']) )
{
$varType = $_POST['traytype'];
}
$term = mysql_real_escape_string($_POST['term']);
$sql = "SELECT * FROM delyn WHERE traytype LIKE '%".$varType."%'";
$r_query = mysql_query($sql);
while ($row = mysql_fetch_array($r_query)){
echo 'ID: ' .$row['ID'];
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'];
echo '<br /> imagename: '.$row['imagename'];
echo '<br /> Tray live: '.$row['traylive'] . ' <br /><br />';
}
?>
</body>