Retrieve data from database in php and display in table format

RetrieveTableData.php preview


RetrieveTableData.php

<!DOCTYPE html>
<html>
    <head>
        <title>Ali-Mirza.blogspot.com</title>
    </head>
    <body>
        <h1>Retrieve Data From DataBase [Ali-Mirza.blogspot.com]</h1>
<?php

$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'mydb';

$con = mysqli_connect($host, $user, $pass, $db);

if(!$con){
    die('Connection Error!');
}else{
    echo '<table border="1"><tr>'
            . '<td>Id</td>'
            . '<td>Name</td>'
            . '<td>Email</td>'
            . '<td>Phone</td></tr>';
    $sql = "SELECT * from user";
    $result = mysqli_query($con,$sql);
    while ($row = mysqli_fetch_array($result)){
        echo '<tr><td>'.$row[0].'</td>'
                . '<td>'.$row[1].'</td>'
                . '<td>'.$row[2].'</td>'
                . '<td>'.$row[3].'</td></tr>';
    }
    echo '</table>';
}
?>

    </body>
</html>

No comments:

Post a Comment