0% found this document useful (0 votes)
14 views1 page

Retrieve

This document connects to a student database, queries for all student data, and outputs it in an HTML table if any results are found, otherwise displaying a message that no records were found.

Uploaded by

Om Kawate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

Retrieve

This document connects to a student database, queries for all student data, and outputs it in an HTML table if any results are found, otherwise displaying a message that no records were found.

Uploaded by

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

<?

php
// Connect to the database
$conn = mysqli_connect("localhost", "username", "password", "student_database");

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

// Retrieve data from the database


$sql = "SELECT * FROM students";
$result = mysqli_query($conn, $sql);

// Check if there are any results


if (mysqli_num_rows($result) > 0) {
// Output data of each row
echo "<h2>Student Data:</h2>";
echo "<table border='1'>";
echo "<tr><th>ID</th><th>Name</th><th>Age</th></tr>";
while ($row = mysqli_fetch_assoc($result)) {
echo
"<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["age"]."</td></tr>";
}
echo "</table>";
} else {
echo "No records found";
}

// Close connection
mysqli_close($conn);
?>

You might also like