Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はなんとか問題を解決し、getAllその後ループしました。しかし、私は mysql クエリなどにあまり詳しくないのでgetAssoc、テーブルから使用する方法があるかどうかを尋ねることにしました。
getAll
getAssoc
A | B | C 1 | 2 | 3 1 | 3 | 4
構造を持つ配列:
$array[1][2]=3 [1][3]=4
これは、あなたの望むことですか
$output = array(); while ($row = mysql_fetch_array($result)){ $first_col = $row['A']; $second_col = $row['B']; $third_col = $row['C']; $output[$first_col][$second_col] = $third_col; }
また、使用しないでくださいmysql_*。PHP はもうサポートしていません。mysqliまたはPDOに切り替えたほうがよい
mysql_*
これを試して
$result = mysql_query('SELECT A,B,C FROM TABLE_NAME'); $out = array(); while ($row=mysql_fetch_array($result)){ $out[] = array($row['A'] => array($row['B']=>$row['C'])); }