我想从firstName
中的成员表中检索z1760359
。当我执行代码时,它只显示成员表中的第一个名称而其余的不显示
Member table in z1760359
select firstName from member
| Roberto |
| Savannah |
| Sai |
| Adarsh |
| Jane |
$hostname='localhost';
$username='root';
$pass='';
$db="z1760359";
$db1=mysqli_connect($hostname,$username,$pass,$db) or die('Oops something went wrong ');
$query= "SELECT firstName from member";
$message1=mysqli_query($db1,$query);
$message2=mysqli_fetch_assoc($message1);
foreach($message2 as $r1)
{
echo"$r1";
echo"<br>";
}
?>
答案 0 :(得分:3)
代码只存储变量的最后一行。试试 -
while($message2=mysqli_fetch_assoc($message1)) {
echo $message2['firstName'];
echo"<br>";
}
使用'while'循环而不是使用foreach
。