hi
after trying out the tutorials on oop by stefan, i then started to convert one of my shopping cart demos using oop php
luckly, i think that i got the hang of it, : this is one of my classes: (if there's anything wrong plz let me know)
class DbCon {
function DbCon($db_host="localhost", $db_user="root", $db_pass="", $db="university") {
mysql_connect($db_host, $db_user, $db_pass)
or die( "Unable to connect to SQL server");
mysql_select_db($db)
or die( "Unable to select database");
$query = "SELECT * FROM kurtula_shop ";
$this->result = mysql_query($query);
}
function viewResult(){
while ($row = mysql_fetch_array($this->result,MYSQL_ASSOC))
{
echo "
$row[item]
$row[description]
$row[price]
/ $row[quantaty]
";
}
}
}//end conect class
the above class, does work fine and defenately can see the advantages of using oop.
however, referring back to the video tutorials, Stefan clearly mentioned that in the class we should not use echo , or set html tags (which does make sense) though would i be right in thinking that this is one of those situations that (as far as basic) there is no other way of achieving the above, other than echoing the html in the class.
Q2: is there a rule of thump into how long a class should be (how many functions should it contain)
Q3: should each class be in a separate file or can they all be in one file? (whats the difference)
thanks a lot