1)这是我的搜索表单
search.html:
<form action="process.php" method="POST">
<input type="text" name="query" />
<input type="hidden" name="searching">
<input type="submit" value="Search" />
</form>
2)我的所有搜索过程都已处理完毕,并将显示在process.php。
上process.php:
<?php
$connection = mysql_connect("*****","*****","*****");
if (!connection) {
die ("Please reload page. Database connection failed: " . mysql_error());
}
// Select a databse to use
$db_select = mysql_select_db("*****",$connection);
if (!$db_select) {
die("Please reload page. Database selection failed: " . mysql_error());
}
if (isset($_POST["searching"])) {
/*call search process*/
dosearch();
}
function doSearch(){
$keyword = $_POST("query");
$search = "SELECT * FROM tbl_name WHERE name LIKE '%$keyword%'";
$result = mysql_query($search) or die('query did not work');
While($result_arr = mysql_fetch_array( $result ))
{
echo $result_arr['name'];
echo " ";
echo "<br>";
echo "<br>";
}
}
?>
3)如何在页面上显示搜索结果&#34; search.html&#34;以及如何将它组合到同一个页面中?
答案 0 :(得分:0)
您必须创建search.php而不是search.html。
您可以尝试使用php会话。他们非常乐于助人。
你可以在$ _SESSION数组中保存你想要从“process.php”转移到“search.php”的变量,然后在search.php中使用它们。例如:
in process.php
<?php session_start();
$_SESSION['a']=$result_arr['name'];
?>
然后在search.php
<?php session_start();
echo $_SESSION['a'];
?>