I would like to display the information in the database using php but need the table to be styled using bootstrap 3 and not the default html table tag. I need assistance to fix this challenge so that i can have a better understanding of how to display search results using php. Thanks
<?php
$connect = mysqli_connect("localhost", "root", "", "oas");
if ($connect) {
$search = "";
$query = "SELECT distinct(M.`s_id`) as `s_id`,
M.`s_mark`,
U.`s_name`
FROM `t_usermark` as M
JOIN `t_user_data` as U on M.s_id = U.s_id WHERE `s_name` like '%$search%'";
$result = mysqli_query($connect, $query);
if ($result) {
if (mysqli_num_rows($result) > 0) {
echo "
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Mark</th>
</tr>
";
while ($row = mysqli_fetch_array($result)) {
$id = $row['s_id'];
$mark = $row['s_mark'];
$name = $row['s_name'];
echo "
<tr>
<td>$id</td>
<td>$name</td>
<td>$mark</td>
</tr>
";
// echo "<p>$id</p><p>$mark</p><p>$name</p>";
}
} else {
echo "No results";
}
echo "</table>";
} else {
echo mysqli_error($connect);
}
} else {
echo "Database connection failed";
}
?>
try this
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<title>Search result </title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<?php
$connect = mysqli_connect("localhost", "root", "", "oas");
if ($connect) {
$search = "";
$query = "SELECT distinct(M.`s_id`) as `s_id`,
M.`s_mark`,
U.`s_name`
FROM `t_usermark` as M
JOIN `t_user_data` as U on M.s_id = U.s_id WHERE `s_name` like '%$search%'";
$result = mysqli_query($connect, $query);
if ($result) {
if (mysqli_num_rows($result) > 0) {
echo "<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Mark</th>
</tr>
";
while ($row = mysqli_fetch_array($result)) {
$id = $row['s_id'];
$mark = $row['s_mark'];
$name = $row['s_name'];
echo '<tr>
<th scope="row">'.$id.'</th>
<td>'.$name.'</td>
<td>'.$mark.'</td>
</tr>';
}
echo '
</tbody>
</table>';
} else {
echo "No results";
}
echo "</table>";
} else {
echo mysqli_error($connect);
}
} else {
echo "Database connection failed";
}
?>
Not going to do it for you but, Add the class table to the table tag then it will be styled using the Bootstrap styling.