0% found this document useful (0 votes)
4 views3 pages

Assign 2

Uploaded by

Khaled Al zaky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Assign 2

Uploaded by

Khaled Al zaky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Advanced database system

Dr. yazeed alsayed


assignment 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).

2- We need to create a connection using PHP using this syntax:

$con = mysqli_connect('localhost', 'root', '','assignment_1');

3- Then write the query syntax you want to apply to retrieve data from the database and execute it:

$stmt = $con->prepare("select * from test");


$stmt->execute();

4- Then declare a variable to save the result in it:

$result=$stmt->get_result();

5- Then creating loop, so all the data could be shown, and organize them in a table:

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>"

- so the final code will be as follow:

<!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.

You might also like