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'])); }