Posts: 219
Location: UK, East Anglia
|
I am now having a few problems with classes and mysql queries.
This is an example of the kind of thing i am doing, but it doesn't work:
PHP Code:
<?php class class1 { var $variable = "1"; }
class class2 { var $_obj; function class2($obj){ $this->_obj=$obj; } functionquery() { $select_array = mysql_query("SELECT * FROM `table` WHERE `message_id` <= '$this->_obj->variable'") or die(mysql_error()); while ($get_array = mysql_fetch_array($select_array)) { echo $get_array['message']."<br>"; } } } $class1 = new class1(); $class2 = new class2($class1); $variable = $class2->query(); ?>
To get it to work i have to:
PHP Code:
<?php class class1 { var $variable = "1"; }
class class2 { var $_obj; function class2($obj){ $this->_obj=$obj; } functionquery() { $variable = $this->_obj->variable; $select_array = mysql_query("SELECT * FROM `table` WHERE `message_id` <= '$variable'") or die(mysql_error()); while ($get_array = mysql_fetch_array($select_array)) { echo $get_array['message']."<br>"; } } } $class1 = new class1(); $class2 = new class2($class1); $variable = $class2->query(); ?>
Why is that?
Last edited by timsquash5; 07-25-2006 at 09:22 AM..
|