mysql table:
+-------------------+----------------+
| config_name | config_value |
+-------------------+----------------+
| allow_autologin | 1 |
| allow_md5 | 0 |
+-------------------+----------------+
current php codes:
$sth = mysql_query("SELECT ...");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print_r($rows);
current result:
Array
(
[0] => Array
(
开发者_JAVA百科[config_name] => allow_autologin
[config_value] => 1
)
[1] => Array
(
[config_name] => allow_md5
[config_value] => 0
)
)
I want to get the result like that:
Array(allow_autologin => 1, allow_md5 => 0)
just add to your results like so:
$sth = mysql_query("SELECT ...");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[$r['config_name']] = $r['config_value'];
}
print_r($rows);
while($r = mysql_fetch_assoc($sth)) {
$rows[] = array($r['config_name'] => $r['config_value']);
}
$sth = mysql_query("SELECT ...");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[$r['config_name']] = $r['config_value'];
}
print_r($rows);
精彩评论