php和ajax搜索功能有问题 [英] Having trouble with php and ajax search function

查看:40
本文介绍了php和ajax搜索功能有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 php/ajax/mysql 还是很陌生.无论如何,我正在创建一个搜索功能,它可以正确返回我正在寻找的数据.

I am still quite new to php/ajax/mysql. In anycase, I'm creating a search function which is returning properly the data I'm looking for.

简而言之,我设置了一个 mysql 数据库.一个具有搜索功能的php网站.我现在正在尝试添加一个指向 mysql 数据库搜索的链接,而不仅仅是显示结果.

In brief, I have a mysql database set up. A php website that has a search function. I'm now trying to add a link to a mysql database search rather than just showing the results.

在我的 search.php 中,echo 行工作正常,但 $string .= 没有返回任何内容.我只是想获得与回声相同的结果,但带有指向 mysql php 记录的链接.我错过了一些简单的东西吗?

In my search.php, the echo line is working fine but the $string .= is not returning anything. I'm just trying to get the same as the echo but with the link to the mysql php record. Am I missing something simple?

//echo $query;
$result = mysqli_query($link, $query);
$string = '';

if($result) {
    if(mysqli_affected_rows($link)!=0) {
        while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
            echo '<p> <b>'.$row['title'].'</b> '.$row['post_ID'].'</p>';
            $string .= "<p><a href='set-detail.php?recordID=".$row->post_ID."'>".$row->title."</a></p>";
        }
    } else {
        echo 'No Results for :"'.$_GET['keyword'].'"';
    }

推荐答案

$row 是一个数组,而不是一个对象,你必须使用 $row['title'] 或 mysqli_fetch_object() 而不是 mysqli_fetch_array().

$row is an array, not an object, you have to use $row['title'] or mysqli_fetch_object() instead of mysqli_fetch_array().

事实上,您已经在 echo 中使用了正确的语法,但在 $string 中却没有使用.

In fact you're already using the correct syntax in your echo but not in $string.

当然,$string 需要输出到某处...

Of course, $string needs to be outputed somewhere...

这篇关于php和ajax搜索功能有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆