php 简单内容查询代码 利用sql like模糊查询
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script language="javascript教程">
check111cnNet()
{
var keyword = myfm.keyword.value;
if( keyword =='' )
{
alert('www.jiaochengji.com提示你:请输入要查询的内容');
return false;
}
}
</script>
</head>
<body>
<form id="myfm" name="myfm" method="post" action="">
<label>
输入查询关键字:
<input type="text" name="keyword" />
</label>
<label>
<input type="submit" name="Submit" value="提交" onClick="return check111cnNet();" />
</label>
</form>
</body>
</html>
<?php
// 创建数据库教程连接
mysql教程_connect('localhost','jquerycn.cn','www.jiaochengji.com');
mysql_select_db('www.jiaochengji.com');//数据库选择
mysql_query('set names "gbk"');
//进度查询操作
if($_POST)
{
$keyword = $_POST['keyword'];
$sql = "Select * from search where title like '%$keyword%' limit 0,10";
$query = mysql_query($sql ) or die("www.jiaochengji.com提示你:查询出错了");
if( mysql_num_rows( $query ) )
{
while( $rs = mysql_fetch_array( $query ) )
{
echo $rs['title'];
}
}
else
{
echo '没有要找的内容';
}
}
/*
数据表结构
CREATE TABLE `111cnNet`.`test` (
`id` INT( 8 ) NOT NULL AUTO_INCREMENT ,
`title` CHAR( 150 ) NULL ,
`content` TEXT NULL ,
PRIMARY KEY ( `id` )
) ENGINE
*/
//函数解析
mysql_connect //数据库连接了有三个参数分别为 数据库服务器名称,用户名,密码
mysql_select_db//参数有二个,第二个可选 ,第一个数据库名称,第二个数据库连接$connwww.jiaochengji.com
mysql_query('set names "gbk"'); //这一句比较重要,就是设置读取数据库内容的编码了,这句要设置与文档编辑一致,否则可能出现乱码。
mysql_query //数据查询,有二个参数,第一个必须,为sql查询语句。
mysql_num_rows //统计mysql_query查询记录多少条,返回为int型
mysql_fetch_array //读取当前记录集一条记录保存到数组。
$_POST
if else
while
// 纯本站原创转载必须注明来源否则必究责任 来源http://www.jiaochengji.com/phper/php.html
?>
您可能感兴趣的文章:
sql模糊查询实例详解
php 简单内容查询代码 利用sql like模糊查询
有关sql模糊查询的介绍
php高性能接口怎么设计
mysql语句带参数模糊查询匹配问题
有关mysql单表多关键字模糊查询的方法介绍
mysql正则匹配模糊查询某个字段
mysql模糊查询语句用法举例
mysql索引优化实例(单列索引与组合索引)
在MySQL中如何进行全文搜索的方法介绍