Hi.
I have follow two classes
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);
}
}
I try to write ..VALUES(\"$this->arr[game_id]\",\"$this->arr[pl_id]\")"
, or
VALUES(".$this->arr[game_id].",".$this->arr[pl_id].")"
,but its does not working.
Thanks for any advise
I 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);
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";
}
}
...
}
And after this in class B I can write the follow
private 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