我正在创建一个搜索栏,它将从我的数据库表的每一列中搜索查询,并将使用php和mysqli提示输出我这样做但现在我不知道如何显示我的输出。有谁能够帮我 这是我的代码
if(!$db) {
require("includes/db.php")
echo 'ERROR: Could not connect to the database.';
} else {
if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);
if(strlen($queryString) >0) {
$query = $db->query("SELECT * FROM mdb WHERE name LIKE '%" . $queryString . "%' OR grno LIKE '%". $queryString ."%'
OR `address` LIKE '%". $queryString ."%', `city` LIKE '%". $queryString ."%' OR pin LIKE '%". $queryString ."%'
OR mobile LIKE '%". $queryString ."%' OR `email` LIKE'%". $queryString ."%' ORDER BY vouchno LIMIT 8");
if($query) {
$catid = 0;
while ($result = $query ->fetch_object()) {
//no idea how do I show the result here
}
答案 0 :(得分:0)
只是为了回答你的问题,这是代码
if(!$db) {
require("includes/db.php")
echo 'ERROR: Could not connect to the database.';
} else {
if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);
if(strlen($queryString) >0) {
$query = $db->query("SELECT * FROM mdb WHERE name LIKE '%" . $queryString . "%' OR grno LIKE '%". $queryString ."%'
OR `address` LIKE '%". $queryString ."%', `city` LIKE '%". $queryString ."%' OR pin LIKE '%". $queryString ."%'
OR mobile LIKE '%". $queryString ."%' OR `email` LIKE'%". $queryString ."%' ORDER BY vouchno LIMIT 8");
if($query) {
$catid = 0;
$results = array();
while ($result = $query ->fetch_object()) {
//no idea how do I show the result here
$results[] = $result;
}
/* use the $results to show the result using foreach or forloop*/
但请考虑以上评论。