Answers for "how to display data from mysql database in php"

PHP
17

query sql in php

$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
Posted by: Guest on February-05-2020
0

how to display data from mysql database into html table using php

<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM Persons");

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>
Posted by: Guest on February-06-2021
1

how to fetch data from database in php

<?php
  ////////////neha jaiswal///
$serve="localhost";
$user="root";
$password="";
$db="neha";
$con=mysqli_connect($serve,$user,$password,$db);
 if ($con) {
 echo "connection success"; 
 }else
{echo "connection unsuccess"; }
 $query="SELECT * FROM product";
 $result=$con->query($query);
 if($result->num_rows>0){
 	while($row=$result->fetch_assoc())
 	{
 		echo $name=$row['name'];
 		echo $qty=$row['qty'];
 		echo	$price=$row['price'];
 		echo	$image=$row['image'];
 	}
 }

?>
Posted by: Guest on January-16-2021

Code answers related to "how to display data from mysql database in php"

Browse Popular Code Answers by Language