1
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)如何顯示在頁面「search.html」以及如何將其合併到同一個頁面的搜索結果?
如果你需要的.html(或者你不想刷新頁面) - 阿賈克斯,如果你不需要.html - >簡單的將文件轉換爲.php,添加代碼,並將'action'值留空。 – sinisake
你到底想做什麼? – MegaMind