In this tutorial I will help you, how to select record from MySQL database and fetch all result in view table page in your PHP project using MySQli query. It is the simple and easy process, which I will show you with an example and source code.
At first connect database using mysqli in PHP. Now select all data using mysqli from MySQL table in PHP. If you using mysql query for select record or fetch record in PHP project, so it’s simple use for you. Fetch result in your table page using while loop.
Example and source code:
database connection:
$con=mysqli_connect(‘localhost’,’root’,’password’,’Database Name’);
Select and Fetch Data
<tbody>
<?php
$i=1;
$qryx=mysqli_query($con,”SELECT * from `Table Name`”);
while($row=mysqli_fetch_array($qryx))
{
?>
<tr>
<th scope=”row”><?php echo $i; ?></th>
<td><?php echo $row[’1’]; ?></td>
<td><?php echo $row[’3’]; ?></td>
<td><?php echo $row[’2’]; ?></td>
<td><?php echo $row[’4’]; ?></td>
</tr>
<?php $i++; } ?>
</tbody>
It’s very simple.
Just select data from your table and fetch all data in a loop and show in a html table:
$con = //connect your database here
$qry = ($con,”SELECT * from `table_name` order by id DESC”);
$row = mysqli_num_rows($qry);
if($row>0){
while $data = mysqli_fetch_assoc($qry){
echo $data[’table_column_name’];
}