Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn=mysqli_connect($dbhost,$dbuser,$dbpass);
$result = mysqli_query($conn,"SELECT * FROM raja");
?>
<!DOCTYPE html>
<html>
 <head>
 <title> Retrive data</title>
 </head>
<body>
<?php
if (mysqli_num_rows($result) > 0) {
?>
  <table>
  
  <tr>
    <td> Name</td>
    
    <td>Email id</td>
  </tr>
<?php
$i=0;
while($row = mysqli_fetch_array($result)) {
?>
<tr>
    <td><?php echo $row["name"]; ?></td>
    <td><?php echo $row["email"]; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
 <?php
}
else{
    echo "No result found";
}
?>
 </body>
</html>


What I have tried:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp64\www\dat3.php on line 15
Posted
Updated 30-Mar-20 7:13am

mysqli_query()[^] returns boolean FALSE if the query fails. You must check the return value before using it as a parameter for any mysqli call that expects a mysqli_result.
 
Share this answer
 
Your connection to the database is missing the fourth important parameter, the data / name of the database to which you want to connect.
Try It:

<pre>$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '123456';
$dbname = "" ;// your name of db
$conn = new mysqli ($dbhost,$dbuser,$dbpass, $dbname);
$conn -> set_charset("utf8");


?>
<!DOCTYPE html>
<html>
 <head>
 <title> Retrive data</title>
 </head>
<body>
<?php
if ($result = $conn -> query("SELECT*FROM example")) {
?>
  <table>

  <tr>
    <td> Name</td>

    <td>Email id</td>
  </tr>
<?php
$i=0;
while($row = mysqli_fetch_array($result)) {
?>
<tr>
    <td><?php echo $row["name"]; ?></td>
    <td><?php echo $row["email"]; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
 <?php
}
else{
    echo "No result found";
}
?>
 </body>
</html>
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900