Using PHP to access the database--paging function and multi-condition query function

Source: Internet
Author: User
Tags button type wrapper

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.