Node and PHP Select or Filter Data With MySQLi

How to Search Using MYSQL select and filter

Every website or app needs to have the ability for any user to preform a search, especially when there are tons of contents available on that website. MySQL filter quest or select query helps us to perform such operations, so we are are going to use nodejs to do this. Make sure you have already connected your node js application with mysql using this link. 

But were are going to give two examples, the first example is the one of PHP and the second is the one of node js

For php

$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
$sql = "SELECT id, firstname, lastname FROM MyGuests WHERE lastname='Doe'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
    echo"id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "
} else {
  echo"0 results";


    'SELECT * FROM posts WHERE title LIKE "%' + searchtext + '%"',
    function (err, rows, fields) {
      if (err) throw err; 

With the above is clear that we can successfully make this operations work with our website.