Hello,
So I have been trying to work more and more in OOP so I can get as used to it as I can.
One thing that isn't clear is how to build one class so it uses the results/resource of another. For example, say I have one class that connects to a database:
class db {
function __construct() {
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$result = mysql_query("SELECT * FROM Items")
or die(mysql_error());
}
}
(in the future I would like to pass the column names to the class instead of using the *)
Then I want to use the results from the above class to be used for this:
class listing extends db {
function list_results($this->result) {
$counter = 1;
echo "<ul>";
while($row = mysql_fetch_array($this->result)) {
if ($counter == 1) {
$row_style = "odd";
$counter = 2;
} else {
$row_style = "even";
$counter = 1;
}
echo "<li class=\"$row_style\"> <ul> \n" ;
echo "<li>" . $row["ItemTitle"] . "</li>";
echo "</li> </ul>";
}
echo "</ul>";
}
}
by creating the instance:
$output = new listing;
$output->list_results()
what am I missing?
Do I need an interface or do I extend like above?
Thanks