Fetch results from MySQL table using PHP:
In PHP fetch results from MySQL table using while loop in your PHP website. Select user result from MySQL table apply PHP select query and get all result in a array variable.
This tutorial I will get all user result using MySQLi select query and fetch results use mysqli_fetch_assoc() in your web page.
Now it’s time to retrieve MySQL table data, which you have inserted in the database using insert query. The MySQL SELECT statement is worked after database connection in the page. So you need to connect database connection or include the database page in the page above. That’s like:
Database Connection:
<?php include "db_connect.php"; ?>
Create a table in the web page, where you fetch the user result. If you follow the example code, you can do it in your web page. So let’s try:
Fetch Result From Database:
<!DOCTYPE html> <html> <head> <title>PHP: Fetch results from MySQL table</title> </head> <body> <table class="table"> <thead> <tr> <th>#</th> <th>Name</th> <th>Email</th> <th>Phone</th> <th>Address</th> </tr> </thead> <tbody> <?php $i=1; $mysqli_qry=mysqli_query($con,"SELECT * from `Table Name`"); while($row=mysqli_fetch_assoc($mysqli_qry)) { ?> <tr> <th scope="row"><?php echo $i; ?></th> <td><?php echo $row['name']; ?></td> <td><?php echo $row['email']; ?></td> <td><?php echo $row['phone']; ?></td> <td><?php echo $row['address']; ?></td> </tr> <?php $i++; } ?> </tbody> </table> </body> </html>
Related posts