我有一个带有 FirstName 和 LastName 列的 mySQL 数据库,目前我有一个搜索 Lastnames 的搜索查询,当 LastNames 匹配时,它们会在屏幕上与它所在行的 FirstName 一起回显,现在太好了,我想找到什么out 是如何使查询搜索输入到输入字段中的 FullNames,请记住,我没有 FullName 列,全名将是用户输入的内容,下面是我目前拥有的示例在职的!谢谢。
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>";
}
}