How to pull search results in php | Logic for pulling search results from database

How to pull search results in php | Logic for pulling search results from database

For logic pulling first of all we need to run the query in the database which is given below

.


alter table `table_name`add FULLTEXT(`title`, `description`);


This query is mendatory to enable fulltext search. Without this query we can't pull the data 
from database.

SELECT * FROM `table_name` WHERE MATCH(title, description) AGAINST ('query')

This will give the desired search results.

<!--php
            $query = $_GET['search'];
            $sql = "SELECT * FROM `table_name`WHERE MATCH(content) AGAINST 
            ('$query')";
            $result = mysqli_query($conn, $sql);
            while($row=mysqli_fetch_assoc($result)){
                $noResults = false;
                echo '
                    <div class="container"-->
                        <p>'.$row['content'].'</p>
                    </div>';
            }

        ?>

$_GET fetch the name from input tag like given below

<form class="d-flex" action="search.php" method="get">
        <input class="form-control me-2" name="search" type="search" 
          placeholder="Search" aria-label="Search">
        <button class="btn btn-info" type="submit">Search</button>
      </form>';



Comments