No keywords are highlight. for what reason behind that. please help me
Here is my HTML code and at the bottom PHP.
HTML CODE:
<form id="nbc-searchblue1" method="post" enctype="multipart/form-data" autocomplete="off">
<input type="text" id="wc-searchblueinput1" class="nbc-searchblue1" value="<?php echo $search; ?>" placeholder="Search Iconic..." name="search" type="search" autofocus>
<br>
<input id='nbc-searchbluesubmit1' value="Search" type="submit" name="button">
</form>
PHP CODE:
<?php
// We need to use sessions, so you should always start sessions using the below code.
session_start();
// If the user is not logged in redirect to the login page...
if (!isset($_SESSION['loggedin']))
{
header('Location: ../index.php');
exit();
}
include 'connect.php';
$search = $sql = '';
if (isset($_POST['button'])){
$numRows = 0;
if (!empty($_POST['search'])){
$search = mysqli_real_escape_string($conn, $_POST['search']);
$sql = "select * from iconic19 where student_id like '%{$search}%' || name_bangla like '%{$search}%' || name like '%{$search}%' || phone like '%{$search}%' || blood like '%{$search}%' || district like '%{$search}%'";
$result = $conn->query($sql);
$numRows = (int) mysqli_num_rows($result);
}
if ($numRows > 0)
{
echo "<table>
<thead>
<tr>
<th><b>Photo</th> <th><b>Student ID</th> <th style='font-weight: 700;'><b>নাম</th> <th><b>Name</th> <th><b>Mobile No.</th> <th><b>Blood Group</th> <th><b>Email</th> <th style=' font-weight: 700;'><b>ঠিকানা</th></tr></thead>";
while ($row = $result->fetch_assoc()){
$student_id = !empty($search)?highlightWords($row['student_id'], $search):$row['student_id'];
$name = !empty($search)?highlightWords($row['name'], $search):$row['name'];
$district = !empty($search)?highlightWords($row['district'], $search):$row['district'];
echo "<tbody>";
echo "<tr>";
echo "<td>" . "<div class='avatar'><a class='fb_id' target='_blank' href='https://www.facebook.com/" . $row['fb_id'] . "'><img src='" . $row['photo'] . "'><img class='img-top' src='fb.png'></a>" . "</td>";
echo "<td data-label='Student ID'>" . $row['student_id'] . "</td>";
echo "<td data-label='নাম' style=' font-weight: 700;'>" . $row['name_bangla'] . "</td>";
echo "<td data-label='Name' style='font-weight:bold;' >" . $row['name'] . "</td>";
echo "<td data-label='Mobile No'>" . "<a href='tel:" . $row['phone'] . "'>" . $row['phone'] . "</a>" . "</td>";
echo "<td data-label='Blood' style='color:red; font-weight:bold;' >" . $row['blood'] . "</td>";
echo "<td data-label='Email'>" . "<a href='mailto:" . $row['email'] . "'>" . $row['email'] . "</a>" . "</td>";
echo "<td data-label='ঠিকানা' style='font-weight: 700;'>" . $row['address_bangla'] . "</td>";
echo "</tr>";
echo "</tbody>";
}
}
else
{
echo "<div class='error-text' style='font-weight: 700;'>No Result</div><br /><br />";
}
}
$result = $conn->query("SELECT * FROM iconic19 $sql ORDER BY id DESC");
function highlightWords($text, $word){
$text = preg_replace('#'. preg_quote($word) .'#i', '<span style="background-color: #F9F902;">\\0</span>', $text);
return $text;
}
$conn->close();
?>