I have a mySQL database with a FirstName and LastName column and presently i have a search query searching for Lastnames, and When the LastNames match they are echoed on screen along with the FirstName from it’s row, Now thats great, what i will like to find out is how can a make the query search for FullNames that are typed into the input feild, keep in mind that i do not have a FullName column the full name will be what the user types in, bellow is an example of what I presently have working! Thanks.
if(isset($_GET['name'])){
$raw_name=$_GET['name'];
if(preg_match("/[A-Z | a-z]+/", $raw_name)){
$name=$raw_name;
include "connect.php";
//-query the database table
$sql="SELECT userId, FirstName, LastName FROM residential2 WHERE FirstName='" . $name ."'";
//-run the query against the mysql query function
$result=mysql_query($sql);
//-count results
$numrows=mysql_num_rows($result);
echo "<div align=\"center\">" . $numrows . " results found for " . stripslashes($name) . "</div>";
while($row=mysql_fetch_array($result)){
$FirstName =$row['FirstName'];
$LastName=$row['LastName'];
$userId=$row['userId'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . "<a href=\"index.php?id=$userId\">" . $LastName . " " .$FirstName . " </a></li>\n";
echo "</ul>";
}
}
else {
echo "<p>Please enter a search query</p>";
}
}
Use
concat()