1.实现分页功能
				?
			
                	
    
	
	
		
		
	
 
	
		
			
	
	 
     
	
			
                 
			
		
		
			
			
			
    
        
        
	
			
						
			
            			
    		
    		
		
	    
    	
    	
        
    	
    
| 
 
								1
 
								2
 
								3
 
								4
 
								5
 
								6
 
								7
 
								8
 
								9
 
								10
 
								11
 
								12
 
								13
 
								14
 
								15
 
								16
 
								17
 
								18
 
								19
 
								20
 
								21
 
								22
 
								23
 
								24
 
								25
 
								26
 
								27
 
								28
 
								29
 
								30
 
								31
 
								32
 
								33
 
								34
 
								35
 
								36
 
								37
						  | 
<body>
<table width="100%" border="1">
<thead>
<tr>
<th>代号</th>
<th>名称</th>
<th>价格</th>
</tr>
</thead>
<tbody>
<?php
require_once "./DBDA.class.php";  //加载数据库访问类的封装文件
require_once "page.class.php";  //加载分页类的封装文件
$db = new DBDA();
$sql = "select count(*) from car";
$arr = $db->query($szts);
$page = new Page($arr[0][0],5);  //查看总数据,并每页显示的行数据
$sql = "select * from car".$page->limit;  //拼接每页显示的数据
$arr = $db->query($sql);
foreach($arr as $v){
echo "<tr>
<td>{$v[0]}</td>
<td>{$v[1]}</td>
<td>{$v[2]}</td>
</tr>";
}
?> 
</tbody>
</table>
<div style="margin-top:20px">
<?php
echo $page->fpage();  //调用分页类的方法
?>
</div>
</body>
 | 
2.实现多条件查询功能
				?
			
	
						
						
						
						
						
						
						
																		
    
        
    
        
                        
                
                    
                
                
                
                    
                
                
                
                    
                
                
                
                    
                
                        
    
 																		
						
																		
    
        
 												
						
																		
	
	
		
				
			
																		
						
						
					
				
				                | 
 
								1
 
								2
 
								3
 
								4
 
								5
 
								6
 
								7
 
								8
 
								9
 
								10
 
								11
 
								12
 
								13
 
								14
 
								15
 
								16
 
								17
 
								18
 
								19
 
								20
 
								21
 
								22
 
								23
 
								24
 
								25
 
								26
 
								27
 
								28
 
								29
 
								30
 
								31
 
								32
 
								33
 
								34
 
								35
 
								36
 
								37
 
								38
 
								39
 
								40
 
								41
 
								42
 
								43
 
								44
 
								45
 
								46
 
								47
 
								48
 
								49
 
								50
 
								51
 
								52
 
								53
 
								54
 
								55
 
								56
 
								57
 
								58
 
								59
 
								60
 
								61
 
								62
 
								63
 
								64
 
								65
						  | 
<body>
<?php
require_once "./DBDA.class.php";
require_once "page.class.php";
$db = new DBDA();
//做一个恒成立的条件
$tj = " 1=1 ";
$tj2 = " 1=1 ";
$name = " ";
$brand = " ";
//当提交的数据不为空,需要改条件
if(!empty($_GET["name"])){
$name = $_GET["name"];
$tj = " name like '%{$name}%' ";  //使用模糊查询查询关键信息
}
if(!empty($_GET["brand"])){
$brand = $_GET["brand"];
$tj2 = " brand = '{$brand}' ";
}
?>
<table width="100%" border="1">
<form action="test.php" method="get">
<input type="text" name="name" placeholder="请输入名称" value="<?php echo $name ?>" style="max-width:200px; float:left">
<input type="text" name="brand" placeholder="请输入系列" value="<?php echo $brand ?>" style="max-width:200px; float:left">
<button type="submit" style="float:left; margin-left:10px">查询</button>
</form>
<thead>
<tr>
<th>代号</th>
<th>名称</th>
<th>系列</th>
<th>时间</th>
<th>价格</th>
</tr>
</thead>
<tbody>
<?php
$zts = "select count(*) from car where {$tj} and {$tj2}";  //多条件查询数据总数
$ats = $db->query($arr);
$page = new Page($ats[0][0],2);
$sql = "select * from car where {$tj} and {$tj2} ".$page->limit;
$arr = $db->query($sql);
foreach($arr as $v){
//给查询的关键字加字体颜色
$n = str_replace($name,"<span style='color:red'>{$name}</span>",$v[1]); 
echo "<tr>
<td>{$v[0]}</td>
<td>{$n}</td>
<td>{$v[2]}</td>
<td>{$v[3]}</td>
<td>{$v[7]}</td>
</tr>";
}
?> 
</tbody>
</table>
<div>
<?php
echo $page->fpage();
?>
</div>
</body>
 | 
以上这篇利用PHP访问数据库_实现分页功能与多条件查询功能的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持快网idc。
原文链接:http://www.cnblogs.com/jly144000/archive/2017/09/04/7476217.html
相关文章
             猜你喜欢
        
        - 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
 - 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
 - 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
 - ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
 - ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
 
			TA的动态
			
		
				- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
 - 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
 - 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
 - 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
 - 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
 
快网idc优惠网
QQ交流群
				您的支持,是我们最大的动力!				
			
		
        热门文章
        
    
    - 
            2025-05-29 28
 - 
            2025-05-29 93
 - 
            2025-06-04 85
 - 
            
在 VPS 服务器上部署 DeepSeek 需要什么配置?怎么部署?
2025-05-25 100 - 
            2025-05-27 33
 
		热门评论
	
	
        
    		
            	
        
        