Andy
Andy

Reputation: 21

Having trouble with php and ajax search function

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

Upvotes: 0

Views: 358

Answers (1)

Capsule
Capsule

Reputation: 6159

$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...

Upvotes: 2

Related Questions