回应多个数据库结果?

时间:2014-08-20 17:01:37

标签: php

我确定这是一种简单易行的方法,但我没有通过Goog(在此处)找到解决方案,但在以下代码中,我希望它能够渲染数据库中的所有匹配项,但它只通过下面的回显线匹配一个("标题"可用于"结帐"在单独的行上)。知道如何才能让它发挥作用吗?

$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;
}
?>

1 个答案:

答案 0 :(得分:1)

您需要遍历结果集

while (!$rs->EOF){ 
    //echo here , then move to the next row
    $rs->movenext();
}

编辑:

//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;