Reputation: 57
I'm sure there's an easy way to do it, but I'm not finding the solution via the Goog (and on here), but in the following code, I want it to render all the matches in the database, but it only matches one via the echo line below ("title" is available for "checkout" on separate lines). Any idea how I can get this to work?
$conn->Open($connString);
$searchquery = $_GET ['search'];
$selectCommand="SELECT * FROM AuthorTitle WHERE title LIKE '%$searchquery%' OR author LIKE '%$searchquery%'";
if(isset($_GET['search'])){
$rs = $conn->Execute($selectCommand);
//opens a recordset from the connection object
if (!$rs->EOF){
$selectCommand=$rs->Fields("ProductID");
$author=$rs->Fields("author");
$title=$rs->Fields("title");
echo "<h2>Search Result for '<b>$searchquery</b>':</h2>
<p><b>$title</b>, $author is available for checkout.</p><br />";
}
else
print "No results found.<br /><br />";
$rs->Close;
}
?>
Upvotes: 1
Views: 50
Reputation: 45490
You need to loop through your resultset
while (!$rs->EOF){
//echo here , then move to the next row
$rs->movenext();
}
EDIT:
//opens a recordset from the connection object
if ($rs->EOF){
print "No results found.<br /><br />";
}else{
while (!$rs->EOF){
$selectCommand=$rs->Fields("ProductID");
$author=$rs->Fields("author");
$title=$rs->Fields("title");
echo "<h2>Search Result for '<b>$searchquery</b>':</h2>
<p><b>$title</b>, $author is available for checkout.</p><br />";
$rs->movenext();
}
}
//close at the end
$rs->Close;
Upvotes: 1