Messing with classes in PHP 4, very new to OOP, anyway I have created the following select class but for some reason I have to manually add the query to the constructor other wise it doesn't work.
$this->query = "SELECT ID, Name FROM tblartists ORDER BY Name ASC LIMIT 10"; is the line that is causing problems as I don't see why I should have to pass it (sort of defeats the point), if I don't include it I get query empty.
PHP Code:
// Select Field (Drop Down)
class form_select_menu {
// Properties
var $name; // Name
var $cssclass; // Css Style
var $query; // sql query
var $opvalue; // db field
var $opname; // db field
// Constructor
function form_select_menu() {
$this->query = "SELECT ID, Name FROM tblartists ORDER BY Name ASC LIMIT 10";
$this->rQuery = mysql_query($this->query) or die(mysql_error());
$this->row_rQuery = mysql_fetch_assoc($this->rQuery);
}
// Output
function display() {
echo "<select name=\"" . $this->name . "\" class=\"" . $this->cssclass . "\">\n";
do {
echo "<option value=\"" . $this->row_rQuery[$this->opvalue] . "\">" . $this->row_rQuery[$this->opname] . "</option>\n";
} while ($this->row_rQuery = mysql_fetch_assoc($this->rQuery));
echo "</select>\n";
}
}
Comment