dsh77114 2014-06-15 15:24
浏览 50

为什么我的搜索栏没有显示结果?

I have made a php search bar before, which worked fine. However, I have recently been developing a one-file web app using the jQuery mobile framework. The aim is to be able to search for a certain trade, person or business, but the results are not showing up. If you search, and there are no results, the message in the output variable prints "There are no results" on the page. The code for the search bar is below:

if(isset($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i", "", "$searchq");

$squery = mysql_query("SELECT * FROM users WHERE name LIKE '%$searchq%' OR fname LIKE '%$searchq%' OR lname LIKE '%$searchq%' OR trade LIKE '%$searchq%' LIMIT 10") or die("Could not search");
$counts = mysql_num_rows($squery);
$output = '';
$outputs = '';

if($counts != 0){
    while($row = mysql_fetch_array($searchq)){
        $ids = $row['id'];
        $fnames = $row['fname'];
        $lnames = $row['lname'];
        $trades = $row['trade'];
        $abouts = $row['about'];
        $emails = $row['email'];
        $numbers = $row['number'];
        $names = $row['name'];

        $output .= '<div>'.$trades.' '.$ids.'</div>';
    }
}else{
    $output = 'Sorry there were no results'; 
    }

}

I print this to the page with:

<h1><?php print($output); ?></h1>

It may also be worth noting that the first feature using php (the sign up form) worked perfectly, but the login form on the same page didn't, and neither does the search bar; I am wondering if having different forms on the same page accessing the same database may cause some kind of problem. If anyone requires any more code, just leave a comment. Thank you in advance.

  • 写回答

2条回答 默认 最新

  • dongxinche1264 2014-06-15 15:28
    关注

    $searchq = preg_replace("#[^0-9a-z]#i", "", "$searchq"); Should be $searchq = preg_replace("#[^0-9a-z]#i", "", $searchq);

    i guess this would work fine now. http://se1.php.net/preg_replace last one should be a variable containing a string and not a string it self.

    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败