国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

利用PHP訪問數據庫_實現分頁功能與多條件查詢功能的示例

2024-05-05 00:00:02
字體:
來源:轉載
供稿:網友

1.實現分頁功能

<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.實現多條件查詢功能

<body><?phprequire_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><?phpecho $page->fpage();?></div></body>

以上這篇利用PHP訪問數據庫_實現分頁功能與多條件查詢功能的示例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 临安市| 青龙| 略阳县| 潮安县| 黑河市| 乐东| 辽中县| 双城市| 遂宁市| 浑源县| 广德县| 宾川县| 融水| 青海省| 洛川县| 隆化县| 永康市| 济宁市| 紫阳县| 南乐县| 沙雅县| 谷城县| 曲沃县| 北票市| 大石桥市| 吴堡县| 拉萨市| 烟台市| 武宣县| 广饶县| 舟山市| 进贤县| 额尔古纳市| 黄陵县| 涞源县| 县级市| 兴义市| 平舆县| 偏关县| 科技| 盘山县|