Data base info as objects
Posted: Sun Aug 08, 2010 3:43 pm
Ok recently been looking into the use of objects, arrays and classes after playing about with the phpbb backend.
currently i have figured out how to rack info up into an array (not hard i know lol but i never used to and it makes things alot neater) and then turn them into objects to use
so now i can access basic info such by doing the following
then displaying them as objects like so
now what i want to know, is how to do the following and if its possable.
I have a configuration table which would appear like so..
Config_option || Config_Value
option 1 || value1
option 2 || value2
etc...
what i want to achive is to load all the comonly used config options into an array, but write the keys (if thats what they are called lol) as the name of the option name. like so and access them as shown
Set them in an array like this...
then access them like
you get the picture.
can anyone explain how and if this is possable to do. thanks
currently i have figured out how to rack info up into an array (not hard i know lol but i never used to and it makes things alot neater) and then turn them into objects to use
so now i can access basic info such by doing the following
Code: Select all
$userResults = $userInfo->query("SELECT username, user_colour, user_lang, user_gender FROM phpbb_users WHERE user_id='$uid'");
$userRow = $userResults->fetch_object();
$playerInfo = (object)array(
'USERNAME' => ($userRow->user_colour != "")? "<font color='#$userRow->user_colour'>$userRow->username</font>" : $userRow->username,
'USER_LANG' => $userRow->user_lang,
'USER_GENDER' => $userRow->user_gender,
);Code: Select all
<?php
echo $lang->GREETING_1 . $playerInfo->USERNAME . $lang->GREETING_2;
?>I have a configuration table which would appear like so..
Config_option || Config_Value
option 1 || value1
option 2 || value2
etc...
what i want to achive is to load all the comonly used config options into an array, but write the keys (if thats what they are called lol) as the name of the option name. like so and access them as shown
Set them in an array like this...
Code: Select all
$config = (object)array(
$option1 => $value1,
$option2 => $value 2
);
Code: Select all
$config->option1;
$config->option2;
can anyone explain how and if this is possable to do. thanks