如何使用while循环获取详细信息并使用foreach显示? 需要使用bind ....
$stmt= $db ->prepare("SELECT quote_autor, quote_text FROM quotes")or die($db->error);
if( $stmt !== FALSE ) {
$stmt->execute();
$stmt->bind_result($quote_autor,$qupte_text);
$records= array();
while($stmt ->fetch()){
$records[]=$stmt ->fetch();
///??????
}
foreach($records as $rec){
//???????
}
答案 0 :(得分:0)
使用while
获取记录:
while($records[] = $stmt ->fetch());
在获取后使用for-each
循环
foreach($records[] as $record) {
echo $record['COLUMN_NAME'];
// use var_dump or print_r to know more
}
如果您要打印所有名称,而不是使用for-each
,您可以执行以下操作:
echo implode(", ", $array);
答案 1 :(得分:0)
$stmt= $db ->prepare("SELECT quote_autor, quote_text FROM quotes")or die($db->error);
if( $stmt !== FALSE ) {
$stmt->execute();
$stmt->bind_result($quote_autor,$qupte_text);
$records= array();
while($dyna=$stmt->fetch()){
array_push($records,$dyna);
}
echo "<table>";
foreach($records as $rec){
echo "<tr><td><b>Autor: ".$row[0]."</b></td><td><p>".$row[1]."</td></tr>";
}
echo "</table>";