現在、下の図のようなデータベースがあります。
number1 が 1 に等しい行を選択するクエリがある場合。
mysql_fetch_assoc()
PHPでは、最初のものしか与えられていませんが、2番目のものを取得する方法はありますか? 次のような次元配列を介してのように
array['number2'][2]
または似たようなもの
現在、下の図のようなデータベースがあります。
number1 が 1 に等しい行を選択するクエリがある場合。
mysql_fetch_assoc()
PHPでは、最初のものしか与えられていませんが、2番目のものを取得する方法はありますか? 次のような次元配列を介してのように
array['number2'][2]
または似たようなもの
mysql_fetch_assoc への繰り返し呼び出しを使用します。これは、PHP マニュアルに記載されています。
http://php.net/manual/function.mysql-fetch-assoc.php
// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
// then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
echo $row["userid"];
echo $row["fullname"];
echo $row["userstatus"];
}
必要に応じて、これを使用して多次元配列を作成し、スクリプトの他の部分で使用できます。