-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax-load.php
More file actions
48 lines (36 loc) · 1.13 KB
/
ajax-load.php
File metadata and controls
48 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "ajaxpractices";
$conn = new mysqli($servername, $username, $password, $database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM students";
$query = mysqli_query($conn, $sql) OR die("SQL query failed");
//variable declared
$output = "";
if (mysqli_num_rows($query) > 0) {
$output = '<div id="table-data" class="mt-3">
<table class="table table-bordered">
<tr>
<th>ID</th>
<th>Name</th>
</tr>';
while ($row = mysqli_fetch_assoc($query)) {
$output .= '<tr>
<td>' . $row["id"] . '</td>
<td>' . $row["first_name"] . '</td>
<td>' . $row["last_name"] . '</td>
</tr>';
}
$output .= '</table></div>';
mysqli_close($conn);
echo $output;
} else {
// No data found
$output = '<div id="table-data" class="mt-3">
<p>No data found</p>
</div>';
}