在我的数据库中,我有这些词:AA、AB、AC、AD、AE、AF、AG
我搜索“AD”为:
<form method="post" action="AF9.php">
<input type="submit" name="submit" value="search">
<input type="text" name="search" />
</form>
我想按字母顺序对数据库中的所有单词进行排序。然后只显示搜索到的值(即AD)和之前的单词和之后的单词。像这样的东西:
- 交流电
- 广告
- AE
这是我到目前为止所写的(非常感谢您的帮助):
<?php
include('includes/db_AF.php'); //includes the db credentials
$connection = @new mysqli(HOSTNAME, MYSQLUSER, MYSQLPASS, MYSQLDB);
if ($connection->connect_error) {
die('Connect Error: ' . $connection->connect_error);
} else {
$search=$_POST["search"];
$query="SELECT word FROM wordtable2
WHERE word like '%'
ORDER BY word ASC"; // I am sorting all the words in the database
$result_obj = '';
$result_obj = $connection->query($query);
while($result = $result_obj->fetch_array(MYSQLI_ASSOC)) {
$items[] = $result;
}
foreach ($items as $item) {
echo $item['word']; //Here I need to echo the results, but don't know how to
}
}
?>