gpt4 book ai didi

php - 在搜索中包含可能的搜索名称的下拉列表

转载 作者:行者123 更新时间:2023-11-30 23:29:39 27 4
gpt4 key购买 nike

我有以下代码,但此代码仅适用于数据库中的完全匹配,我想要的是例如你想搜索“John Jones”,如果你只键入 joh 他的名字以及相同的其他用户姓名将出现在下拉列表中,姓氏将显示为 jone。我已经尝试了几个“LIKE”功能,但我似乎无法弄清楚。谢谢!

<?php
include ('core/init.php');

logged_in_redirect();

if(empty($_POST['friend_search'])) {
header('Location: friends.php');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<title> My Friends</title>
<link href='css.css' rel='stylesheet' type='text/css'/>
</head>
<body class='home-body'>
<?php include_once("core/analyticstrackingcode.php") ?>
<div class='whitebg'>
<?php include('core/navbar.php'); ?>
<?php
$friend = $_POST['friend_search'];
$found=0;
$search = mysql_query("SELECT * FROM users");
while($row = mysql_fetch_array($search)) {
$possible_match_name = $row['first_name'];
$possible_match_id = $row['id'];
$possible_match_email = $row['email'];
$possible_match_profilepic = $row['profilepic'];
$this_users_email = $_SESSION['email'];
if($possible_match_email!=$this_users_email) {
if($friend==$possible_match_email) {
echo "
<html>
<div class='friendsearchentries'>
<img src='$possible_match_profilepic' class='friend-match-prof-pic' />
<a href='confirm_send.php?id=$possible_match_id' class='friend-match-link' ><center>".$possible_match_name."</center></a>
</div>
</html>";
$found=1;
}
}
}
if($found==0) {
echo "Sorry, we found no matches.";
}
?>
</div>
</body>
</html>

最佳答案

您应该在 SQL 查询中改用 LIKE:

http://www.mysqltutorial.org/sql-like-mysql.aspx

关于php - 在搜索中包含可能的搜索名称的下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11388412/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com