伊莉討論區
標題:
請教各PHP高手
[打印本頁]
作者:
gnufihcnahc
時間:
2018-2-26 08:42 AM
標題:
請教各PHP高手
請各高手指教一下自學的我
$query在mysql運行到,不過小弟不懂如何於php內執行,求教,謝謝。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; char=utf-8" />
<title>Search Engine - Search</title>
</head>
<body>
<h2>Search Engine</h2>
<form action='./search.php' method='get'>
<input type='text' name='k' size='50' value='<?php echo $_GET['k']; ?>' />
<input type='submit' value='Search'>
</form>
<hr />
<?php
$k = $_GET['k'];
$terms = explode(" ", $k);
$query = “SELECT * FROM tickertalk.tutorial WHERE MATCH (title,description)against($k)order by match(title,description) against ($k)”;
foreach ($terms as $each){
$i++;
if ($i == 1)
$query .= "title,description LIKE '%$each%'";
else
$query .= "OR title,description LIKE '%$each%'";
}
// Create connection
$conn = new mysqli("localhost", "root", "800709chan");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = $query;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$id = $row['id'];
$title = $row['title'];
$description = $row['description'];
$keywords = $row['keywords'];
$link = $row['link'];
echo "<h2><a href='$link'>$title</a></h2>
$description<br /><br />";
}
} else {
echo "No results found for \"<b>$k</b>\"";
}
$conn->close();
?>
</body>
</html>
作者:
xxskydownxx
時間:
2020-7-10 01:05 AM
你的網址有沒有search.php?k=xxx 的顯示?
GET的意思是從網址上拿資料。
或者說你php有支持mysqli嗎?你可以用phpinfo() 找看有沒有 Mysqli的支持?因為mysql 有兩種不一樣的 Mysql & Mysqli的支持
歡迎光臨 伊莉討論區 (http://a04.eyny.com/)
Powered by Discuz!