Home > Article > Backend Development > PHP database content search (search for specified content and output)_PHP tutorial
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
*/