class array within double quotes

maOzinha

New Member
I have follow two classes \[code\]class A { .... protected $arr = array('game_id','pl_id'); ... } class B extends A { //for example here add method private function add_to_DB() { $query = "INSERT INTO TABLE(game_id,player_id) VALUES(????,????)"; //Here is my question,what I must to write??mysql_query($query);} }\[/code\]I try to write \[code\]..VALUES(\"$this->arr[game_id]\",\"$this->arr[pl_id]\")"\[/code\], or
\[code\]VALUES(".$this->arr[game_id].",".$this->arr[pl_id].")"\[/code\],but its does not working. Thanks for any adviseI think I found another solution of my question.in my A class I must to have _set and _ get methods.
class A
{
....
protected arr = array('game_id'=>NULL,'pl_id'=>NULL); \[code\] function __set($property, $value) { if (array_key_exists($property, $this->arr)) { $this->arr[$property] = $value; } else { print "Error: Can't write a property other than x & y\n"; } } function __get($property) { if (array_key_exists($property, $this->arr)) { return $this->arr[$property]; } else { print "ERROR: write correct property"; } }... } \[/code\]And after this in class B I can write the followprivate function add_to_DB()
{
$query = "INSERT INTO TABLE(game_id,player_id)
VALUES(\"$this->game_id\",\"$this->pl_id\")"; //Here WAS my question
mysql_query($query);
} Thanks for your advise
 
Back
Top