实现原理很简单就是根据用户提交的数据到mysql数据表中查询是否有相同的,有就输出没有就不操作了,这是一款简单的记录搜索代码.
首先我们来创建搜索数据表: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 ;
保存数据,代码如下:insert into `acc`.`search` (
`id` ,
`keyword`
)
values (
null , '内容搜索'
), (
null , 'php站内搜索'
);
数据连接,代码如下:$conn = mysql_connect('localhost','ac','1');//这里的ac用户名,1是密码,修改成你自己的mysql便可
$res = mysql_db_query('abc',"select * from search where keyword='内容搜索' ") or die(mysql_error());
if(mysql_num_rows($res) == 1) {
while($row = mysql_fetch_assoc($res)) {
foreach($row as $key => $val) {
echo $row['keyword'],'
';
}//开源代码phprm.com
}
}
本文原创发布php中文网,转载请注明出处,感谢您的尊重!