简体   繁体   中英

how can I print Select query result on the browser? Not displaying the result fetch from the database

<?php 
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];

if(!$searchtype || !$searchterm)
{ 
echo"you have not entered anything.Pls go back";
exit;
}

if(!get_magic_quotes_gpc())
{ 
  $searchtype=addslashes($searchtype);
  $searchterm=addslashes($searchterm);
}

@$db= new mysqli('localhost','root','mansi','books');
if(mysqli_connect_errno()) 
{ 
echo" Cannot connect to the database";
exit;
}

$query="select * from books where".$serchtype."like '%".$searchterm."%'";
$result=$db->query($query);


$num_results = count($result);

echo"<p>Number of books found:".$num_results."</p>";

     for($i=0;$i<$num_results;$i++)  
 {
      //$row=$result->fetch_assoc();
    $row=mysqli_fetch_assoc($result);

    echo"<p><strong>".($i+1)."Title:";
    echo htmlspecialchars(stripslashes($row['title']));
    echo"</strong><br/> Author";
    echo stripslashes($row['author']);
    echo"<br/> ISBN";
    echo stripslashes($row['isbn']);
    echo"<br/> Price";
    echo stripslashes($row['price']);
    echo"</p>";
}


$db->close();

?>

Program working and printing echo statement like Title,Author,ISBN and Price but not printing value fetch from the database.Program cannot display the result of the query like $row['title] ,$row['isbn'],$row['author'] and $row['price'].

Database name :books. Table name also books.

mysql> select * from books;
+-------------+-----------------+-------------------+-------+
| isbn        | author          | title             | price |
+-------------+-----------------+-------------------+-------+
| 0-672       | Michelle Morgan | Java 2 Developers | 38.49 |
| 0-672-31509 | Pruitt          | Teach GIMP        | 27.49 |
| 0-672-31745 | Thomas Down     | Installing Linux  | 27.49 |
| 0-672-31769 | Thomas Schenk   | Caledra           | 54.99 |
+-------------+-----------------+-------------------+-------+
4 rows in set (0.00 sec)

您查询的“位置”之后和“喜欢”之前需要一个额外的空间

$query="select * from books where ".$searchtype." like '%".$searchterm."%'";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM