0
我有一個數據庫,員工信息顯示到表中,我設法使搜索框,我已連接到我的數據庫,現在一切都是問題,當我搜索名稱,即「丹尼爾」,它只是給我退回了我已經擁有的桌子,所以那裏有兩張桌子,而不是「丹尼爾斯」信息。站點搜索顯示整個表格而不是搜索結果?
在此先感謝非常感謝任何幫助!
我的繼承人代碼 -
<!doctype html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="../Css/index_stylesheet.css">
</head>
<body>
<p>
<?php
$form = "<html>
<h1>Search!</h1>
<form method=\"get\">
<label>Name:
<input type=\"text\" name=\"keyname\" />
</label>
<input type=\"submit\" value=\"Search\" />
</form>
</body>
</html>";
//capture search term and remove spaces at its both ends if there is any
if(!empty($_GET['keyname'])){
$keyname = $_GET['keyname'];
$searchTerm = trim($keyname);
//database connection info
$host = "localhost"; //server
$db = "development_suite"; //database name
$user = "root"; //dabases user name
$pwd = ""; //password
//connecting to server and creating link to database
$link = mysqli_connect($host, $user, $pwd, $db);
//MYSQL search statement
$query = "SELECT firstname ,surname,address,mobile,email
FROM development_suite.eeg_staff;";
$results = mysqli_query($link,$query);
/* check whethere there were matching records in the table
by counting the number of results returned */
if(mysqli_num_rows($results) >= 1){
$output = "$row_1";
while($row = mysqli_fetch_array($results))
{
$output .= "First Name: " . $row['firstname'] . "<br />";
$output .= "Surname: " . $row['surname'] . "<br />";
$output .= "Address: " . $row['address'] . "<br />";
$output .= "Mobile: " . $row['mobile'] . "<br />";
$output .= "Email: " . $row['email'] . "<br /><br />";
}
}else{
$output = "There was no matching record for the name " .
strip_tags($searchTerm);
}
} else {
$output = "Enter name you are searching for.";
}
echo "$form\n$output";
?>
</body>
</html>
感謝喜的幫助!!:d –
我應該把在這行有什麼關係嗎?出現錯誤,「警告:mysqli_num_rows()期望參數1爲mysqli_result,布爾在C:\ wamp \ www \ manholeform \ Application \ includes 49包含\ search_function.php中給出」 –
第49行是if語句,以if (mysqli_num_rows($ results) –