想做一个简单查询功能。通过查询可以得出下面的表格。
需要高手帮我填写PHP代码。
库里这样的
部分代码如下:gb2312
<div align="center">
<select name="select" id="select">
<option value="1">京</option>
<option value="2">黑</option>
<option value="3">沈</option>
</select>
<select name="select2" id="select2">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
<option value="4" selected="selected">D</option>
<option value="99">其它</option>
</select>
<input name="t" type="text" size="15" maxlength="5" value="" />
<input type="submit" name="button" value="查询" />
</div>
<table width="300" border="0" cellpadding="0" cellspacing="0" bgcolor="#C5D5C5" align="center">
<tr><td><table width="100%" border="0" cellpadding="8" cellspacing="1">
<tr>
<td width="25%" bgcolor="#F5F5F5" align="center">车牌号码</td>
<td width="75%" bgcolor="#FFFFFF" align="center" style="font-size:16px;">京Dxxxxxxx</td>
</tr>
<tr>
<td bgcolor="#F5F5F5" align="center">归属地</td>
<td bgcolor="#FFFFFF" align="center" style="font-size:16px;">北京市 </td>
</tr>
</table></td></tr></table>
------解决方案--------------------
注意文本文件的bom头问题。
- PHP code
<?php header('Content-Type:text/html;charset=utf-8'); $head = ''; $ower = ''; $number = ''; if (isset($_POST['button'])) { $head = $_POST['province'].$_POST['letter']; $number = $_POST['t']; $data = array(); $fp = fopen('sql.txt','r'); while (!feof($fp)) { $tmp = fgets($fp); list($key,$value) = preg_split("/[\s]+/", $tmp); $data[] = array($key,$value); } $ower = '没有数据'; foreach ($data as $v) { if ($v[0] == $head) { $ower = $v[1]; break; } } } ?> <!DOCTYPE HTML> <html> <head> <title></title> </head> <body> <form name="form1" action="car.php" method="post"> <div align="center"> <select id="select" name="province"> <option value="京">京</option> <option value="黑">黑</option> <option value="沈">沈</option> </select> <select id="select2" name="letter"> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> <option value="D" selected="selected">D</option> <option value="99">其它</option> </select> <input name="t" type="text" size="15" maxlength="5" value="" /> <input type="submit" name="button" value="查询" /> </div> <table width="300" border="0" cellpadding="0" cellspacing="0" bgcolor="#C5D5C5" align="center"> <tr><td><table width="100%" border="0" cellpadding="8" cellspacing="1"> <tr> <td width="25%" bgcolor="#F5F5F5" align="center">车牌号码</td> <td width="75%" bgcolor="#FFFFFF" align="center" style="font-size:16px;"><?php echo $head.$number;?></td> </tr> <tr> <td bgcolor="#F5F5F5" align="center">归属地</td> <td bgcolor="#FFFFFF" align="center" style="font-size:16px;"><?php echo $ower;?> </td> </tr> </table></td></tr></table> </body> </form> </html>