3

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
        (
            [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)

3 Answers 3

6

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);
Sign up to request clarification or add additional context in comments.

1 Comment

yes. it works. thank you very much. perfect help. A+. thanks. i gotta wait 7 minutes to select your answer..
4
while($r = mysql_fetch_assoc($sth)) {
    $rows[] = array($r['config_name'] => $r['config_value']);
}

Comments

1
$sth = mysql_query("SELECT ...");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
    $rows[$r['config_name']] = $r['config_value'];
}
print_r($rows);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.