本文實例講述了PHP+MySQL實現(xiàn)模糊查詢員工信息功能。分享給大家供大家參考,具體如下:
一、代碼
注意兩點:
1、用Notepad+編輯時,格式選擇:【編碼字符集】->【中文】->【gb2312】
2、
meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
conn.php
?php $connID=mysql_connect("localhost","root","root"); mysql_select_db("db_database13", $connID); mysql_query("set names gbk"); ?>
index.php
?php session_start(); include("conn/conn.php");?> html> head> meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> title> 查詢企業(yè)員工的詳細信息/title> style type="text/css"> !-- .STYLE4 {font-size: 13px} .STYLE5 {font-family: "華文琥珀"; font-size: 20px;} .STYLE6 {color: #990000} --> /style> /head> body> table width="450" height="28" border="0" align="center" cellpadding="0" cellspacing="0"> tr> td align="center" class="STYLE5 STYLE6">查詢企業(yè)員工的詳細信息/td> /tr> /table> form name="form1" method="post" action="?php echo $_SERVER['PHP_SELF']?>"> table width="450" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#990000"> tr> td width="176" align="center" bgcolor="#FFFFFF">span class="STYLE1 STYLE4">按照員工的編號查詢/span>/td> td width="182" bgcolor="#FFFFFF">input name="number" type="text" id="number" />/td> td width="84" height="25" bgcolor="#FFFFFF">input type="hidden" name="flag" value="1" />input name="submit" type="submit" value="提交" />/td> /tr> /table> /form> table width="450" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#990000"> tr> td width="67" align="center" bgcolor="#FFFFFF" class="STYLE4">編號/td> td width="72" align="center" bgcolor="#FFFFFF" class="STYLE4">姓名/td> td width="119" align="center" bgcolor="#FFFFFF" class="STYLE4">電話/td> td width="182" height="25" align="center" bgcolor="#FFFFFF" class="STYLE4">地址/td> /tr> ?php if(isset($_POST["flag"])) { $query=mysql_query("select * from tb_employee where number like '%".$_POST["number"]."%'"); if($query) { while($myrow=mysql_fetch_array($query)) { ?> tr> td align="center" bgcolor="#FFFFFF" class="STYLE4">span class="STYLE2">?php echo $myrow[number];?>/span>/td> td align="center" bgcolor="#FFFFFF" class="STYLE4">span class="STYLE2">?php echo $myrow[name];?>/span>/td> td height="23" align="center" bgcolor="#FFFFFF" class="STYLE4">span class="STYLE2">?php echo $myrow[tel];?>/span>/td> td height="23" align="center" bgcolor="#FFFFFF" class="STYLE4">span class="STYLE2">?php echo $myrow[address];?>/span>/td> /tr> ?php } } } ?> /table> /body> /html>
二、運行結(jié)果
瀏覽器選擇的編碼是gbk
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php+mysql數(shù)據(jù)庫操作入門教程》、《php+mysqli數(shù)據(jù)庫程序設(shè)計技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。