Pages

Friday, 3 February 2017

MySQL Table Record Fetch

Fetch all record from MYSQL Table Using PHP

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Girfa : Student Help :: MySQL Table Record Fetch</title>
</head>

<body>

<?php
$username = "root";

$password = "";
$dbname = "tmp";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM stu";
$result = $conn->query($sql);

if ($result->num_rows > 0)
 {
    // output data of each row
    while($row = $result->fetch_assoc())
{
        echo "<b>Roll:</b> " . $row["roll"]. "&nbsp;&nbsp;&nbsp;&nbsp;<b>Name: </B>" . $row["name"]. "&nbsp;&nbsp;&nbsp;&nbsp;<b> City :</B> " . $row["city"]. "<br>";
    }
}
 else
 {
    echo "0 results";
}
$conn->close();
?>



</body>
</html>

No comments:

Post a Comment