我一直试图输出表中的所有数据,但是当我这样做时,它只输出第一个数据。我希望它使用amfphp在我的flash应用程序中输出。但它只输出第一行:
if (mysqli_num_rows($result) > 0) {
$sql = "SELECT * FROM chatStorage";
$result = mysqli_query($conn, $sql);
$able = true;
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_array($result)) {
return $row["user"].": ".$row["chatText"];
}
}
}
答案 0 :(得分:0)
您需要显示所有值,使用print或echo:
$sql = "SELECT * FROM chatStorage";
$result = mysqli_query($conn, $sql);
$able = true;
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_array($result)) {
print $row["user"].": ".$row["chatText"].PHP_EOL;
}
}
或者如果要返回索引的数组:
$sql = "SELECT * FROM chatStorage";
$result = mysqli_query($conn, $sql);
$able = true;
$myarray = array();
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_array($result)) {
$myarray[$row["user"]][] = $row["chatText"];
}
}
return $myarray;