My table is setup like this:
id | config_name | config_value
1 | language | English
2 | currency | $
3 | date_format | M d, Y
etc…
I’m trying to query the database to use this information as needed throughout a page. There may be 100 rows in this table, but I only need to use specific ones on a page. That’s why I need to specify which one(s) I’m using. For example:
$config->language; would echo “English”
$config->currency; would echo “$”, etc.
How would I set this up?
I know how to get the values and echo the same thing over and over again in a while loop:
$systemconfig = mysql_query("SELECT config_name, config_value FROM system_config");
while($configs = mysql_fetch_array( $systemconfig )) {
echo "The value of ".$configs['config_name']."is: ".$configs['config_value'];
} // end while
… but I don’t want to be stuck in that loop as it cycles through all the configs in the database. That’s why I would like to be able to echo the specific config values I specify throughout the page like mentioned above, ie: $config->language
Could someone enlighten me?
Well this is pretty straight forward, you have to walk yourself through the thought process:
Here is a rough object example (you fill in the code needed):