这是我的代码....尝试过echo the $sql
但它显示' %Search%
'...但我想将它用作$Search
..请帮助...
以下是我的整个搜索代码...
if(isset($_POST['search']))
{
$search=$_POST['search'];
$criteria=$_POST['criteria'];
$table='alumni';
mysql_real_escape_string($search);
if($criteria=='ALL')
{
$sql="SELECT UNAME FROM `alumni` ";
$result=mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
while ($row=mysql_fetch_array($result))
{
echo"<tr><td><a>".$row['UNAME']."</a></td></tr>";
}
}
if($criteria=='UNAME' || $criteria=='FNAME' || $criteria=='BATCH')
{
//echo $criteria;
$sql="SELECT UNAME FROM `alumni` WHERE ".$criteria." LIKE '%".$search."%'";
//echo $sql;
$result=mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
while ($row=mysql_fetch_array($result))
{
echo"<tr><td><a>".$row['UNAME']."</a></td></tr>";
}
}
}
?>