<?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);
?>
<?php
$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "dbname";
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
$sql = "SELECT * FROM dbname;";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo $row['sql_row_name'] . "<br>";
}
}
?>
<?php
$host = "127.0.0.1"; //IP of your database
$userName = "root"; //Username for database login
$userPass = ""; //Password associated with the username
$database = "example-database"; //Your database name
$connectQuery = mysqli_connect($host,$userName,$userPass,$database);
if(mysqli_connect_errno()){
echo mysqli_connect_error();
exit();
}else{
$selectQuery = "SELECT * FROM `tbl_users` ORDER BY `user_id` ASC";
$result = mysqli_query($connectQuery,$selectQuery);
if(mysqli_num_rows($result) > 0){
}else{
$msg = "No Record found";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>HTML and PHP code</title>
</head>
<body>
<h1>Display user list using HTML and PHP</h1>
<?=$msg;?>
<table border="1px" style="width:600px; line-height:40px;">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Status</th>
<th>Registrating Date</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_assoc($result)){?>
<tr>
<td><?php echo $row['user_firstName'].$row['user_lastName']; ?></td>
<td><?php echo $row['user_email']; ?></td>
<td><?php if($row['user_status'] == 1){
echo "Active";
}else{
echo "Deactive";
} ?></td>
<td><?php echo $row['user_registrationDate']; ?></td>
<tr>
<?}?>
</tbody>
</table>
</body>
</html>