tags:

views:

22

answers:

1

i have table called config contian config_name | config_value know i want to extract it like that

`config_name` | `config_value`
`articles_limit` | `10`

now i want php code give me an array like that articles_limit => 10

+1  A: 

You might like to try using a database wrapper like ADODb, where such a thing would simply be

$config=$db->GetAssoc('select config_name, config_value from config');

As plain PHP, this would something like this

$config=array();
$result = mysql_query('select config_name, config_value from config'); 
if (!$result) 
{
    //handle error
    die(mysql_error());
}
else
{
    while ($row = mysql_fetch_assoc($result)) 
    {
        $config[$row['config_name']] = $row['config_value'];
    }
    mysql_free_result($result);
}
Paul Dixon
no i will not use it please tell me the useally way
moustafa
well the usual way would be to use a wrapper rather than write all that!
Paul Dixon
New programs should use the mysqli extension.
Artefacto