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;
}
PHPマニュアルで説明されているように、フェッチは行のみをフェッチするため:
結果セットから次の行を取得します
mysql_ コードを PDO 用に変更することをお勧めします
$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
}