- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
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>";
}
}
最佳答案
使用concat()
$sql="SELECT userId, CONCAT(FirstName, ' ', LastName) AS fullname FROM residential2 WHERE FirstName='" . $name ."'";
<?php
$fullname = $row['fullname'];
?>
关于php - 如何组合 sql 表中的 2 列来搜索全名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11002850/
我正在尝试用此人的全名填充 Yii2 中的下拉列表,名字和姓氏在我的数据库中的不同列中。 在我的个人表中 编号 名字 姓氏 dep_id (fk) ... 在我的 Person.php 模型中有 pu
我目前正在像这样连接名字和姓氏(使用 PostgreSQL): concat(customers.firstname, ' ', customers.lastname) 我在这里遇到的问题是我的客户只
从 (new Date()).toString() 返回的字符串看起来像这样: "Tue Nov 22 2016 14:14:51 GMT-0800 (Pacific Standard Time)"
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
已经将近 3 天了,我仍然无法修复该错误。简单的情况,我想搜索人名(姓名和姓氏)。 示例: 首先我写给 John(结果:John Newman、John Stable、John Carens) 然后我
我在我的项目中使用 Laravel 5.3,我试图获取多个列并在 View 的下拉选择元素中显示数据。我正在做这样的查询: $users = User::select( DB:
我目前正在使用此脚本从给定路径中提取名称、文件夹、文件夹名称: Get-ChildItem "C:\user\desktop" | Select Name, ` @{ n = 'Folde
我通过在 ApplicationUser 中添加几个字段扩展了 ASP NET 身份架构。派生自 IdentityUser 的类.我添加的字段之一是 FullName . 现在,当我写 User.Id
我正在开发一个 Android 应用程序,其中任何使用我们的应用程序登录到 Facebook 的 Android 用户,我需要从 Facebook 中提取他的照片、他的性别和他的全名。我正在为此使用
我是一名优秀的程序员,十分优秀!