PHP MySQL: Querying fetch Data from Database

Today, We want to share with you fetch data from database in php.In this post we will show you how to get data from database in php using id, hear for how to retrieve data from database in php using mysqli we will give you demo and example for implement.In this post, we will learn about how to retrieve data from database in html form using PHP with an example.

how to display data from database in php in table?

There are the Following The simple About how to fetch data from database in php and display in table Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to fetch data from database in php and display in html table, so the how to get data from database using api in php is used for this example is following below.

Read Also:  Laravel 6 List All Files in Directory Examples

i have a database named crud_mvc, a table named products. Now, here is the PHP full source code to fetch data from database and display in an HTML table.

index.php

 
<?php 

$user = 'root'; 
$password = ''; 

// Database name is crud_mvc 
$database = 'crud_mvc'; 

$servername='localhost:3308'; 
$mysqli = new mysqli($servername, $user, 
				$password, $database); 

if ($mysqli->connect_error) { 
	die('Connect Error (' . 
	$mysqli->connect_errno . ') '. 
	$mysqli->connect_error); 
} 

$sql = "SELECT * FROM products ORDER BY score DESC "; 
$result = $mysqli->query($sql); 
$mysqli->close(); 
?>  
<!DOCTYPE html> 
<html lang="en"> 

<head> 
	<meta charset="UTF-8"> 
	<title>crud_mvc User Details</title> 
	<style> 
		table { 
			margin: 0 auto; 
			font-size: large; 
			border: 1px solid black; 
		} 

		h1 { 
			text-align: center; 
			color: #006600; 
			font-size: xx-large; 
			font-family: 'Gill Sans', 'Gill Sans MT', 
			' Calibri', 'Trebuchet MS', 'sans-serif'; 
		} 

		td { 
			background-color: #E4F5D4; 
			border: 1px solid black; 
		} 

		th, 
		td { 
			font-weight: bold; 
			border: 1px solid black; 
			padding: 10px; 
			text-align: center; 
		} 

		td { 
			font-weight: lighter; 
		} 
	</style> 
</head> 

<body> 
	<section> 
		<h2>Pakainfo.com Free Download PHP Projects</h2> 

		<table> 
			<tr> 
				<th>crud_mvc UserHandle</th> 
				<th>Practice Problems</th> 
				<th>Coding Score</th> 
				<th>crud_mvc Articles</th> 
			</tr> 
			<?php 
				while($rows=$result->fetch_assoc()) 
				{ 
			?> 
			<tr>  
				<td><?php echo $rows['membername'];?></td> 
				<td><?php echo $rows['problems'];?></td> 
				<td><?php echo $rows['score'];?></td> 
				<td><?php echo $rows['articles'];?></td> 
			</tr> 
			<?php 
				} 
			?> 
		</table> 
	</section> 
</body> 

</html> 

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about fetch data from database in Laravel.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.