我试图让我的数据库可以通过部分关键词进行搜索,也可以按 col 标题升序排序。但是,当我输入可搜索代码时,输入名称时没有返回结果,而且它似乎把可排序代码弄乱了,它不想在表格中正确对齐,也不想当我点击它时排序col标题?
这是我的可搜索代码:
<?php
$db=mysql_connect("localhost","dispute_admin","xxxxxx");
$mydb=mysql_select_db("dispute_credit");
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/[0-9a-zA-Z]+/",$_POST['name'])){
$name=$_POST['name'];
$sql=mysql_query("SELECT * FROM disputes WHERE company LIKE '%$company%', OR account_num LIKE '%$account_num%', OR type LIKE '%$type%'") or die(mysql_error());
$result=mysql_query($sql);
if(isset($_GET['go']))
{
if($_GET['go']=='company'){
$sql="SELECT * FROM disputes WHERE company LIKE '%" .$name . "'%";
}
elseif
($_GET['go']=='account_num'){
$sql="SELECT * FROM disputes WHERE account_num LIKE '%" .$name . "'%";
}
elseif
($_GET['go']=='type'){
$sql="SELECT * FROM disputes WHERE type LIKE '%" .$name . "'%";
}
}
WHILE($row=mysql_fetch_array($result)){
echo 'Company: '.$row['company'];
echo 'Account Num: '.$row['account_num'];
echo 'Type: '.$row['type'];
echo "<ol>\n";
echo "<li>" . "<a href=\"disputes.php=$company\">" . $account_num . " " . $type . " </a></li>\n";
echo "</ol>";
}
}
else{
echo "Please enter search words!";
}
}
}
?>