很多站长朋友们都不太清楚php++搜索查询,今天小编就来给大家整理php++搜索查询,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php搜索查询数据库数据 2、 php如何查找文件 3、 PHP—strpos查找字符串 4、 PHP中怎么实现关键字搜索? 5、 php搜索查询数据库 6、 PHP实现搜索查询功能的方法技巧 php搜索查询数据库数据查看一下代码:
<?php
// 获取表单提交值
$student_id = intval(trim($_POST['student_id']));
// 页面表单 可以放单独的html文件中,如果放单独的html页面中 form 的action的地址要改成下面的PHP文件名
echo '<form action="" method="post">
<input type="text" name="student_id" value="{$student_id}"/>
<input type="submit" name="submit" value="查询"/>
</form>';
// 当有数据提交时
if ($student_id)
{
$con= mysql_connect("localhost","root","111") or die("连接错误");
mysql_select_db("examination",$con);
// 查询
$sql = "SELECT * FROM tablename WHERE student_id = $student_id ";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
// 输出
echo '学号:'.$row['student_id'].'<br>姓名:'.$row['name'].'<br>性别:'.$row['gender'].'<br>分数:'.$row['score'];
}
?>
php如何查找文件通过报错信息我们能够看到('failed to open stream','Failed opening required'),这是被包含的文件无法打开。造成这种错误原因有两个。
1、在source_index.php这个文件同级目录下面没有function.php这个文件。
2、或者是require_once(data/function.php);这条语句写错了,造成无法定位到正确的目录。我在下面再给你介绍一下目录定位的一些知识。
2.1、require_once("data/function.php");
意思是:调用source_index.php所处目录下的data目录下面的function.php文件。
2.2、require_once("/data/function.php");
意思是:调用source_index.php所在目录根目录下面的data目录下面的function.php文件。
2.3、require_once("data/function.php");
意思是:调用source_index.php上一级目录下面的data目录下面的function.php文件。
2.4、require_once("./data/function.php");
意思是:调用source_index.php当前目录下的data目录下面的function.php文件,与require_once("data/function.php");该条语句的作用是一样的。
希望上面的知识能帮你解决这个问题。
PHP—strpos查找字符串strpos——查找字符串第一次出现的位置
strpos(string \$haystack, mixed \$needle, int \$offset = 0):int
返回needle在haystack中首次出现的数字位置
offset(7.1.0开始支持负数的 offset。)
如果提供了此参数,搜索会从字符串该字符数的起始位置开始统计。 如果是负数,搜索会从字符串结尾指定字符数开始 。
返回值:
返回 needle 存在于 haystack 字符串起始的位置(独立于 offset)。同时 注意字符串位置是从0开始,而不是从1开始的 。
如果没找到 needle,将返回 false。
注意:
PHP中怎么实现关键字搜索?PHP要实现关键字查搜索,需要用到like关键字来组合查询条件
like具体实现方法如下:
例一:
1 $userForm=M('user');
1 $where['name']=array('like','phpernote%');
2 $userForm->where($where)->select();
这里的like查询即为:name like 'phpernote%'
例二:
1$where['name']=array('like',array('%phpernote%','%.com'),'OR');
这里的like查询即为:name like '%phpernote%' or name like '%.com'
例三:
1$where['name']=array(array('like','%a%'),array('like','%b%'),array('like','%c%'),'phpernote','or');
这里的like查询即为:(`name` LIKE '%a%') OR (`name` LIKE '%b%') OR (`name` LIKE '%c%') OR (`name` = 'phpernote')
例四:
1$where['_string']='(name like "%phpernote%") OR (title like "%phpernote")'
这里的like查询即为:name like '%phpernote%' or title like '%phpernote'
php搜索查询数据库1.action 后面的页面没有指定
2.if($name) 改成 if($name!=‘’)
3.把$sql 打印出来
4.页面报错内容是什么
完善上面4项,纠错毫无压力。
PHP实现搜索查询功能的方法技巧下面是首页显示数据表package中的内容,但是有个条件,显示在首页的内容还必须是 :字段status=0,且printing=0的数据才能在首页列表中显示出来。
页面上有一个“搜索”功能,输入条件后就会根据条件来进行查询。
一般的搜索的话,只要在首页显示列表方法index()中给一个:
?
$map=array();//初始化查询条件
$map=$this->_search();//调用查询方法
$total = $this->Model->where ($map)->count(); //这个主要是用来计算页面显示数据条数的
if ($total == 0) {
$_list = '';
} else {
$_list = $this->Model->where ($map)->limit( $post_data ['first'] . ',' . $post_data ['rows'] )->select();
}
然后,就是写一个_search():
protected function _search(){
$map = array ();
$post_data = I ( 'post.' );
if ($post_data ['packageid'] != '') {
$map ['packageid'] = array (
'like',
'%' . $post_data ['packageid'] . '%'
);
}
return $map;
}
最后,在设置的“搜索”菜单中,调用这个搜索方法。
但是,这个搜索的.同时,还要确保在字段status=0,且printing=0的数据中进行搜索。
这个限制条件该加在什么地方。各种尝试和查询后,才知道。限制条件直接加在SQL语句中就行了(如下红色的地方)。(我自己试的时候一直在如下蓝色的地方加条件,屡试屡败!)
$map=array();
$map=$this->_search();
$total = $this->Model->where ($map)->where(array('status' =>0,'print_status'=>0))->count();
if ($total == 0) {
$_list = '';
} else {
$_list = $this->Model->where ($map)->where(array('status' =>0,'print_status'=>0))->limit( $post_data ['first'] . ',' . $post_data ['rows'] )->select();
}
更多相关文章推荐:
关于php++搜索查询的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php++搜索查询 php搜索框查询数据库的详细内容...