0
votes

So basicly im coding a search page where people search for people Every account has 2 rows for their names eg. John Doe is stored into 2 rows in people table firstname = John and lastname = Doe So my question is when i search for someone when they type John it will return John Doe but if someone types in the full name "John Doe" it will return nothing So how could i merge 2 rows the firstname and lastname into one like this

mysqli_query($con, "SELECT firstname,lastname FROM people WHERE firstname AND     lastname = '$searchquery'");

This above is just an example of how i need it to be

2
Just out of curiosity, why would you make a user have two rows to store first and last name instead of one row that has those two columns? - Rasclatt
"John Doe" is stored in two rows? You then describe the data as having the fields in two columns. Please edit your question with sample data and desired results. - Gordon Linoff

2 Answers

0
votes

Use CONCAT_WS. Try this:

mysqli_query($con, "SELECT firstname,lastname FROM people WHERE CONCAT_WS(' ',firstname, lastname) = '$searchquery'");
0
votes

In MySQL you can merge strings, like this:

SELECT firstname,lastname FROM people WHERE CONCAT(firstname,' ',lastname) = '$searchquery'

You can also try this:

SELECT firstname,lastname FROM people WHERE '$searchquery' LIKE CONCAT('%',firstname,'%',lastname,'%')