Assign 2
Assign 2
Khaled Mahmoud
Ci893
In this paper I am going to show you how to view data from database into a webpage.
1- Firstly, we need to create database (we have finished this step in the first assignment).
3- Then write the query syntax you want to apply to retrieve data from the database and execute it:
$result=$stmt->get_result();
5- Then creating loop, so all the data could be shown, and organize them in a table:
<!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">
<title>Document</title>
</head>
<body>
<?php
$con = mysqli_connect('localhost', 'root', '','assignment_1');
$stmt = $con->prepare("select * from test");
$stmt->execute();
$result=$stmt->get_result();
echo "<table border>";
while($row=$result->fetch_assoc()){
echo "<tr><td>".$row["ID"]."</td><td>".$row["Fname"]."</td><td>".
$row["adress"]."</td></tr>";
};
echo "</table>"
?>
</body>
</html>
6- Then save the file and name it "tesst.php" and put it in the "hdocs" file, and go to web browser and
write "localhost/test.php" this page will come:
Notice all the data from the database are organized and shown in a webpage.