You are on page 1of 1

Here we using 3 file for view data from MySql database using Ajax.

database.php
view_ajax.php
view.php
Table user_data
CREATE TABLE `crud` (
`id` int(11) NOT NULL,
`name` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`phone` varchar(100) NOT NULL,
`city` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
database.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db="school";
// Create connection
$conn = mysqli_connect($servername, $username, $password,$db);
?>
view_ajax.php
<?php
include 'database.php';
$sql = "SELECT * FROM crud";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
?>
<tr>
<td><?=$row['name'];?></td>
<td><?=$row['email'];?></td>
<td><?=$row['phone'];?></td>
<td><?=$row['city'];?></td>
</tr>
<?php
}
}
else {
echo "0 results";
}
mysqli_close($conn);
?>

You might also like