我有以下代码,但此代码仅适用于数据库中的精确匹配,我想要的是例如你想搜索“约翰琼斯”,如果你只输入 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>