<?php
include "./dbda.class.php";
$db = new dbda();
$sql1 = "";
$value = "";
if(!empty($_POST["name"]))
{
$name = $_POST["name"];
$sql1 = " where Name like '%{$name}%'";
$value = $name;
}
?>
<h1>汽车查询界面</h1>
<form action="chaxun.php" method="post">
<div>请输入名称:<input type="text" name="name" value="<?php echo $value;?>" /> <input type="submit" value="查询" /></div>
</form>
<br />
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>代号</td>
<td>名称</td>
<td>油耗</td>
<td>功率</td>
<td>价格</td>
</tr>
<?php
$sql = "select * from car".$sql1;
$attr = $db->Query($sql);
foreach($attr as $v)
{
$a = "<span style='color:red'>{$value}</span>";
$str = str_replace($value,$a,$v[1]);
echo "<tr>
<td>{$v[0]}</td>
<td>{$str}</td>
<td>{$v[4]}</td>
<td>{$v[5]}</td>
<td>{$v[7]}</td>
</tr>";
}
?>
</table>
<?php
class dbda
{
public $host = "localhost";
public $uid = "root";
public $pwd = "";
public function Query($sql,$type=0,$db="mydb")
{
$d = new MySQLi($this->host,$this->uid,$this->pwd,$db);
!mysqli_connect_error() or die("连接失败!");
$result = $d->query($sql);
if($type==0)
{
return $result->fetch_all();
}
else
{
return $result;
}
}
}