您好在我的php代码中mysql仅获取1结果,而不是全部,请帮助我为什么这样做是我的代码
$requesthost = "SELECT * FROM tblvhost";
$reshost = mysql_query($requesthost);
while($rowhost=mysql_fetch_array($reshost)) {
$hostvid = $rowhost['vh_id'];
$hostname = $rowhost['vh_name'];
}
最佳答案
您将在每次循环迭代中覆盖数据:
while($rowhost=mysql_fetch_array($reshost)) {
$hostvid = $rowhost['vh_id']; // overwritten
$hostname = $rowhost['vh_name']; // overwritten
}
要收集所有数据,您可能希望将它们附加到数组中:
$hostvid = array();
$hostname = array();
while($rowhost=mysql_fetch_array($reshost)) {
$hostvid[] = $rowhost['vh_id']; // insert into array
$hostname[] = $rowhost['vh_name']; // insert into array
}