Reputation: 1885
SELECT id, CONCAT(lastname,', ',firstname) AS fullname, lastname, firstname
FROM " . TABLE_CONTACT . "
WHERE
CONCAT(firstname,' ', lastname) LIKE '%$goTo%' OR
CONCAT(firstname,' ', middlename,' ', lastname) LIKE '%$goTo%' OR
nickname LIKE '%$goTo%'
ORDER BY fullname";
Can anyone please tell me what is purpose of above query ? I am new to mysql so unable to understand it. Thanks
Upvotes: 0
Views: 276
Reputation: 38115
It will query the DB and get the id
and create a full name CONCAT(lastname,', ',firstname)
from both first and last name fields and also return them separately lastname, firstname
FROM the contacts table TABLE_CONTACT
WHERE the variable passed %$goTo%
should match:
Imagine this record in the DB:
id firstname lastname middlaname nickname
5454 Ibrahim Faour Ali ifaour
1- CONCAT(firstname,' ', lastname)
= Ibrahim Faour
2- OR CONCAT(firstname,' ', middlename,' ', lastname)
= Ibrahim Ali Faour
3- nickname
= ifaour
And them order them by the newly created column fullname
Upvotes: 3
Reputation: 17350
it will search for contacts, by nickname, or fullname, or fullname with initial. Also, it will return them in alphabetical order.
Upvotes: 5