How to Search First Name and Last Name in PHP MySQL?


Share:
 | Published By: Admin | Published On: Feb 05, 2022 | Category: PHP

Hello Friends,

I am going to explain you example of how to search first name and last name in PHP? . You will learn how to get first name and last name in PHP query. I would like to how to get first name and last name. This article will give you simple example of get first name and last name from full name in PHP.

We will use get search first name and last name PHP. You can understand a concept of search first name and last name PHP.

You can see both example of how to search first name and last name use PHP.

Table: users

So, let's see bellow solution:

index.php
<?php

$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "db_php";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

$sql = "SELECT 
            id, CONCAT(first_name, ' ',last_name) as full_name, email, created_at FROM 
        `users`
            WHERE CONCAT(first_name, ' ',last_name) LIKE 'Nikhil thu%'";

$result = $conn->query($sql);

while ($row = $result->fetch_assoc()) {
    echo '<pre>';
    print_r($row);
}

?>
Output:
Array
(
    [id] => 1
    [full_name] => Nikhil Thumar
    [email] => nikhil001@gmail.com
    [created_at] => 2022-02-01 10:43:55
)
It will help you...
Share: