MySQL Forums
Forum List  »  Newbie

Trying to return all results as well as count of another select statement
Posted by: Daniel Iser
Date: July 14, 2009 11:04PM

MySQL Version - 5.1.33-community

ok im trying to build a dynamic menu setup and the way i want to go about it is to get the following from a single table

table is as follows

-- ----------------------------
-- Table structure for menu
-- ----------------------------
DROP TABLE IF EXISTS `menu`;
CREATE TABLE `menu` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`label` varchar(50) NOT NULL DEFAULT '',
`link_url` varchar(100) NOT NULL DEFAULT '#',
`parent_id` int(11) NOT NULL DEFAULT '0',
`sort_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=latin1;

Ok, so what i want returned is

ID | LABEL | LINK_URL | PARENT_ID | SORT_ID | COUNT1


COUNT1 is where this is tricky.. i have tried using COUNT and GROUPBY but i am either not doing it right or i am needing something else

I want COUNT1 to return the number of other row where parent_id = ID of the current row so that if there is a submenu it will return > 0. If not it returns zero. Then i can loop that with php to echo the proper format for my menu.

Options: ReplyQuote


Subject
Written By
Posted
Trying to return all results as well as count of another select statement
July 14, 2009 11:04PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.