php 搜索练习
<?php require_once("connect.php"); if(isset($_GET['submit'])){ $name=$_GET['name']; $age=$_GET['age']; $wherelist=[]; if(!empty($_GET['name'])){ $wherelist[]=' name like "%'.$_GET['name'].'%" '; } if(!empty($_GET['age'])){ $wherelist[]=' age like '.$_GET['age']; } if(count($wherelist)>0){ $where=' where'.implode(" and ", $wherelist); mysql_query("set names utf8"); $ser_query='select * from demotb'.$where; $resul=mysql_query($ser_query); while ($rows=mysql_fetch_assoc($resul)) { # code... echo "<table>"; echo "<tr><td>".$rows['name'].'</td><td>'.$rows['age'].'</td></tr>'; echo "</table>"; } } } ?> <form action="search.php" method="get"> <label for="name">Name:</label><input type="text" name="name"> <label for="age">Age:</label><input type="text" name="age"> <p><input type="submit" name="submit" value="Search"></p> </form>
posted on 2013-06-03 15:41 Ijavascript 阅读(156) 评论(0) 编辑 收藏 举报