Having trouble with php and ajax search function

南楼画角 提交于 2020-01-16 14:21:33

问题


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.

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.

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'].'"';
    }

回答1:


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

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

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



来源:https://stackoverflow.com/questions/5092524/having-trouble-with-php-and-ajax-search-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!