0

I am unable to print out a mysqli binded result.

bind_result($variable)

Every thing in the code seems to work fine, except the display of the binded result.

For example:

If the mysqli query finds 3 results with the search term "Dog", then the following is displayed:

 Results: 
 Results: 
 Results: 

This tells me that everything but the bind_result is working.

The desired display would be would be:

Results: Dog
Results: Fog
Results: Log

Below is my code:

$title = "%".$searchValue."%";

//search by Title
$query = "SELECT Title, ID
      FROM Title
      WHERE Title LIKE ?";

$stmt = $conn->prepare($query);
$stmt->bind_param('s',$title);
$stmt->execute();       

$stmt->bind_result($titleResult); //This is not binding, rest works.

while ($stmt->fetch()) {
    echo "Results: ";
    echo $titleResult; //This does not echo, rest works.
    echo "</br>";
}
seamus
  • 2,681
  • 7
  • 26
  • 49
  • i think you are not defining 's' in your code – Saty Apr 12 '15 at 09:51
  • example of using ['bind_result' - /18753262/example-of-how-to-use-bind-result-vs-get-result](http://stackoverflow.com/questions/18753262/example-of-how-to-use-bind-result-vs-get-result). – Ryan Vincent Apr 12 '15 at 12:51

1 Answers1

0

I was selecting two columns.

$query = "SELECT Title, ID

But only binding one result.

$stmt->bind_result($titleResult); 

Should have been:

 $stmt->bind_result($titleResult, $id); 
seamus
  • 2,681
  • 7
  • 26
  • 49