0

I am creating a search bar which will search the query from every column of my database table and will prompt the output I am doing this with php and mysqli but now I dont have any idea to how do I show my output. can anybody help me here is my code

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
                }
4

1 回答 1

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*/

但请考虑上面的评论。

于 2013-05-02T15:45:16.407 回答