1. Realize paging function
<body>
<table width= "100%" border= "1" >
<thead>
<tr>
<th> Code </th>
<th> name </th>
<th> Price </th>
</tr>
</thead>
<tbody>
<?php
Require_once "./dbda.class.php"; Loading the wrapper file for the database access class
Require_once "page.class.php"; Load the wrapper file for the paging class
$db = new Dbda ();
$sql = "SELECT count (*) from car";
$arr = $db->query ($szts);
$page = new Page ($arr [0][0],5); View total data, and the row data displayed per page
$sql = "SELECT * from Car". $page->limit; Stitching the data displayed on each page
$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 (); To invoke a method of the paging class
?>
</div>
</body>
2. Implement multi-criteria query function
<body>
<?php
Require_once "./dbda.class.php";
Require_once "page.class.php";
$db = new Dbda ();
To do a constant set of conditions
$TJ = "1=1";
$TJ 2 = "1=1";
$name = "";
$brand = "";
When the submitted data is not empty, you need to change the condition
if (!empty ($_get["name"])) {
$name = $_get["name"];
$TJ = "name like '%{$name}% '"; Querying key information with fuzzy queries
}
if (!empty ($_get["brand")) {
$brand = $_get["brand"];
$TJ 2 = "brand = ' {$brand} '";
}
?>
<table width= "100%" border= "1" >
<form action= "test.php" method= "Get" >
<input type= "text" name= "name" placeholder= "Please enter the name" value= "<?php echo $name?>" style= "max-width:200px; Float:left ">
<input type= "text" Name= "brand" placeholder= "Please enter series" value= "<?php echo $brand?>" style= "max-width:200px; Float:left ">
<button type= "Submit" style= "FLOAT:LEFT; margin-left:10px "> Inquiries </button>
</form>
<thead>
<tr>
<th> Code </th>
<th> name </th>
<th> Series </th>
<th> Time </th>
<th> Price </th>
</tr>
</thead>
<tbody>
<?php
$zts = "SELECT count (*) from car where {$TJ} and {$TJ 2}"; Multi-Criteria Query data total
$ats = $db->query ($arr);
$page = new Page ($ats [0][0],2);
$sql = "SELECT * from car where {$TJ} and {$TJ 2}". $page->limit;
$arr = $db->query ($sql);
foreach ($arr as $v) {
Add font color to the keyword of the query
$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>
Using PHP to access the database--paging function and multi-condition query function