谁能告诉我为什么 MySQL 的所有结果都没有出现在数组中?
$result = mysql_query("select * from groups order by id desc");
if ($row = $result->fetch()) {
$groups[] = $row;
}
while
不使用if
while ($row = $result->fetch()) {
$groups[] = $row;
}
您在那里的代码不会迭代结果集。试试这个。
while ($row = $result->fetch()) {
$groups[] = $row;
}
因为 fetch 只获取一行,如php 手册中所述:
从结果集中获取下一行
我想建议您更改 PDO 的 mysql_ 代码
$db = new PDO("..."); // Creates the PDO object. Put the right arguments for your connection.
$statement = $db->prepare("SELECT * FROM groups ORDER BY id DESC");
$statement->execute();
while ($groups = $statement->fetch())
{
// Do whatever you want to do
}