让mysql数据库可搜索和排序?

时间:2013-05-15 18:00:00

标签: php

我试图让我的数据库可以通过关键词的一部分进行搜索,也可以通过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!";

}

}

}

?>

0 个答案:

没有答案