Home > Backend Development > PHP Tutorial > PHP fuzzy query example code

PHP fuzzy query example code

WBOY
Release: 2016-07-29 09:14:44
Original
1772 people have browsed it

header("content-type:text/html;charset=utf-8");
//Get user data
$keywords=$_POST['keywords'];
//Connect to the database
$c or die('Database link failed');
//Select the database and set the character set
mysql_select_db('search');
mysql_set_charset('utf8');
//php fuzzy query
if(empty($keywords )){
$str= "Please enter the content you want to query";
}else{
$sql="SELECT * FROM user WHERE username LIKE '%$keywords%'";
}
$rs=mysql_query($sql );
$users = array();
while($row=mysql_fetch_assoc($rs)){
//Highlight replacement
$row['username'] = str_replace($keywords, ''.$keywords.'', $row['username']);
$users[] = $row;
}
//print_r($users);
?>




php fuzzy query


User query for php fuzzy queryer



User name:

if($keywords){
echo '

Query keywords '.$keywords.' The result is:

';
if($users){
echo " ";
echo "";
foreach ($ users as $key => $value){
echo "";
echo "";
echo "< td>".$value['username']."";
echo "";
echo "< td>".$value['email']."";
echo "";
echo "< /tr>";
}
echo "
UIDGenderEmailInterests
".$value['uid']."".$value['sex']."".$value['hobby']."
";
}else {
echo "No relevant user found";
}
}else{
echo "

".$str."


";
}
?>

The above introduces the PHP fuzzy query example code, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template