Home >Backend Development >PHP Tutorial >PHP database content search (search for specified content and output)_PHP tutorial

PHP database content search (search for specified content and output)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:04:471633browse

The implementation principle is very simple: query the mysql data table based on the data submitted by the user to see if there is the same one. If there is, it will output and no operation will be performed. This is a simple record search code.

php tutorial database tutorial content search (search for specified content and output)
/*
First let’s create the search data table
create table if not exists `search` (
`id` int(4) not null auto_increment,
`keyword` varchar(500) not null,
primary key (`id`)
) engine=myisam default charset=utf8 auto_increment=1 ;

Save data

insert into `acc`.`search` (
`id` ,
`keyword`
)
values ​​(
null , 'Content search'
), (
null , 'php site search'
);

*/

//Data connection

$conn = mysql tutorial_connect('localhost','ac','1');//The ac user name here, 1 is the password, just change it to your own mysql

$res = mysql_db_query('abc',"select * from search where keyword='content search' ") or die(mysql_error());

if(mysql_num_rows($res) == 1) {
while($row = mysql_fetch_assoc($res)) {
foreach($row as $key => $val) {
echo $row['keyword'],'
';
}
}
}

/*
The implementation principle is very simple. It is to query the mysql data table based on the data submitted by the user to see if there is the same one. If there is, it will output and no operation will be performed. This is a simple record search code.
Original reprints on this site indicate the source www.bKjia.c0m
*/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630829.htmlTechArticleThe implementation principle is very simple: according to the data submitted by the user, query whether there are the same ones in the mysql data table, and output if there are any. If not, it won't work. This is a simple record search code. p...
Statement:
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