Fetching Data From SQL Database and Display in Rows
geez@caz.com |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../styles.css">
<title>Fetching a Database Array</title>
</head>
<body>
<h1 class="lesson-h1">Fetching an Array From a Database</h1>
<?php
include('../connection.php');
$title = "Fetching Data From SQL Database and Display in Rows";
echo "<p>$title</p>";
$sql = mysqli_query($link, "SELECT * FROM `users` ORDER BY id ASC");
$row = mysqli_fetch_array($sql);
// Limit Controls Number of Columns Displayed
$limit = 2;
$count= 0;
echo "<table border='1'>";
while ($row = mysqli_fetch_array($sql)){
$email = $row['email'];
if($count < $limit){
if ($count == 0){
echo "<tr>";
}
echo "<td>$email</td>";
} else {
$count = 0;
echo "</tr><tr><td>$email</td>";
}
$count++;
}
echo "</tr></table><hr>";
include('../show_code.php');
show_code('index.php');
?>
</body>
</html>