robsonrdasilva Posted June 27, 2011 Share Posted June 27, 2011 Hey, what's up? I'm making a site control panel and I've a question about a product listing. I'm using a DAO class (ProductDAO), which became all register of products from MySQL database. The structure of this class is (for example): class ProductDAO { public function get_products() { $sql = 'SELECT * FROM products'; $query = mysql_query($sql); return mysql_fetch_object($query, 'Product'); } } And the Product class class Product { private $id_product; private $id_category; private $name; } It is working very well, the function get_products return a array of products with class Product, but now I need to look for the category name from each product. The class Category has the structure: class Category { private $id_category; private $name; } And to return a category name I change my function get_products: class ProductDAO { public function get_products() { $sql = 'SELECT products.*, categories.name as category_name FROM products INNER JOIN categories ON products.id_category = categories.id_category'; $query = mysql_query($sql); return mysql_fetch_object($query, 'Product'); } } But in class Product I don't have the variable category_name. How do I return those products to listing? I need to create a DAO class for categories and for each item of products that I list in my site I look for the specific category? Sorry, my english isn't so good. Thanks. Link to comment https://forums.phpfreaks.com/topic/240548-how-i-look-for-to-categories-of-products-using-data-acess-object/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.