I want to use php to print out something from database, but I don't know how to do the select. Please give me a hand. This is my table: CREATE TABLE IF NOT EXISTS `category` ( `category_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `parent` int(11) NOT NULL, PRIMARY KEY (`category_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ; PHP: INSERT INTO `category` (`category_id`, `name`, `parent`) VALUES (1, 'Category', 0), (2, 'Subcategory', 1), (3, 'Tv ', 2), (4, 'Plasma Tv', 3), (5, 'Old Tv', 3), (6, 'Radio', 2), (7, 'New Radio', 6), (8, 'Old Radio', 6), (9, 'Blue Radio', 6), (10, 'Green Radio', 6); PHP: I want to select to print out 1. only the Category: Tv and Radio 2. only the Subcategorylasma Tv,Old Tv,New Radio, Old Radio,Blue Radio,Green Radio Someone please tell me how will look those 2 mysql select. Thank you.
Hi, try this: <?php // Select records where parent is = 2 and 6 and select category_id = 3 $query = mysql_query('SELECT * FROM `category` WHERE `parent` = "2" OR `parent` = "6" OR `category_id` = "3"'); while ($row = mysql_fetch_assoc($query)) { var_dump ($row); } ?> PHP:
for category, use this statement: "select name from category where parent = 2" for subcategory use: "select name from category where parent = 6 or parent =3"