So here is a table of categories, implemented unlimited nesting

CREATE TABLE IF NOT EXISTS `articles_cat_baby` ( `id` int(11) NOT NULL auto_increment, `realid` int(11) NOT NULL, `refid` int(11) NOT NULL default '0', `name` text NOT NULL, `text` text NOT NULL, `kartinka` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

Table of articles

 CREATE TABLE IF NOT EXISTS `articles_baby` ( `id` int(11) NOT NULL auto_increment, `id_user` int(11) NOT NULL, `id_cat` int(11) NOT NULL, `name` text NOT NULL, `text` longtext NOT NULL, `moderation` int(1) NOT NULL default '2', `time` int(11) NOT NULL, `prosmotrov` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

Count the number of articles in the category - mysql_result (mysql_query ("SELECT COUNT (*) FROM articles".$prefixbaby." WHERE id_cat = '". $ Row [' id ']. "';"), 0)

Question: how to count the number of articles in the parent category?

    1 answer 1

    Something like this:

     SELECT COUNT(*) AS cnt FROM articles_cat_baby AS c, articles_baby AS a WHERE c.id = $id AND a.id_cat = c.refid 

    PS: You have terrible column names

    • Similarly. - vitagame