我有一個表格,其中包含所有必要的字段(ID,姓名等)檢索搜索結果| PHP&SQL
在搜索php文件中,當您鍵入ID時,它會顯示與此ID相對應的所有信息,例如(ID = 1,name = Jack)
我的想法:當我在php中進行自定義搜索時,我想添加一個鏈接到另一個顯示相同搜索結果但帶有其他信息的php文件的鏈接。
問題:如何從其他php文件調用自定義搜索結果?
關於此示例,如果我搜索ID = 2,我想鏈接到另一個顯示該自定義搜索的更多信息的php文件「Extrainfo.php」。
這裏是我使用的代碼:
//database connection
global $conn;
$servername = "localhost"; //host name
$username = "root"; //username
$password = ""; //password
$mysql_database = "info"; //database name
//mysqli prepared statement
$conn = mysqli_connect($servername, $username, $password) or die("Connection failed: " . mysqli_connect_error());
mysqli_select_db($conn,$mysql_database) or die("Opps some thing went wrong");
if(isset($_GET['idNumber']))
{
$IDNUMBER =$_GET['idNumber'];
$stmt = $conn->prepare("select * from madea where idNumber=? ");
$stmt->bind_param('s',$IDNUMBER);
$stmt->execute();
$val = $stmt->get_result();
$row_count= $val->num_rows;
if($row_count>0)
{
$result =$val->fetch_assoc();
echo $result['idNumber'];
echo $result['name'];
}
else
{
echo "identification_number not Match";
}
$stmt->close();
$conn->close();
// Probably need to save the variable to call in the other php file?
$idNumber = $result['idNumber'];
}
?>
<a href="extrainfo.php">Extrainfo</a>
'問題:我如何從其他php文件調用自定義搜索結果?'好吧,您通過'_ _GET'發送了一些不被建議的東西。但是你會'header(「Location:page.php?idNumber = search term」)' – IsThisJavascript
@ WillParky93我應該使用post方法嗎?或者你認爲我是最好的選擇。 非常感謝:) – Dann
是的使用後。如果你使用post,你將無法足夠的標題,但你總是可以使用'ajax'來查詢你的php頁面。 – IsThisJavascript