做了个搜索框,请问怎样将搜索到的匹配数据显示在页面上

乱世中的单纯 发布于 2015/05/19 20:47
阅读 569
收藏 0
PHP
搜索框的代码:

<input type="search" name="name2" value="请输入关键字" onMouseOver="this.focus()" onBlur="if (value ==''){value='请输入关键字'}" onFocus="this.select()" onClick="if(this.value=='请输入关键字')this.value=''"> 



返回搜索结果的页面:
<?php
error_reporting(0); 
$db=mysql_connect("localhost","rfid","rfid"); 
$select=mysql_select_db("rfid2",$db); 



$_sql="SELECT * FROM info WHERE tagID LIKE '%name2%' OR name1 LIKE '%name2%' OR type1 LIKE '%name2%' OR manufacturer LIKE '%name2%' OR classification LIKE '%name2%' OR buyDate LIKE '%name2%' OR ManufactureDate LIKE '%name2%' OR unit LIKE '%name2%' OR buyer LIKE '%name2%' OR amount LIKE '%name2%'; ";
mysql_query("set names utf8");//编码设置为utf8
$query=mysql_query($_sql);
echo "<table>";
while($row=mysql_fetch_array($query))

//从数据库查询出来的字段
$data1=$row["tagID"];
$data2=$row["name1"];
$data3=$row["type1"];
$data4=$row["manufacturer"];
$data5=$row["classification"];
$data6=$row["buyDate"];
$data7=$row["ManufactureDate"];
$data8=$row["buyer"];
$data9=$row["unit"];
$data10=$row["amount"];
//将数据放到html的表格中
echo "<tr><td>$data1</td><td>$data2</td><td>$data3</td><td>$data4</td><td>$data5</td><td>$data6</td><td>$data7</td><td>$data8</td><td>$data9</td><td>$data10</td></tr>";
}
echo "</table>";
?>

但是搜索的时候,页面什么也不出来。怎么回事?是不是不应该写LIKE '%name2%'?

加载中
0
houhuiliang
houhuiliang
'%name2%'应该是'%".$_REQUEST['name2']."%';
乱世中的单纯
乱世中的单纯
太感谢了!!!
0
梦想岛
梦想岛
先学学 $_REQUEST,$_GET,$_POST
返回顶部
顶部