Cita:
lo que quiero es contar todos los POST que pertenecen a un foro en especifico para saber la cantidad de temas actuales disponibles en el mismo. He hecho esta consulta: Post:
CREATE TABLE `post` (
`idpost` int(6) unsigned NOT NULL auto_increment,
`idtopic` int(6) default NULL,
`idforo` int(6) default NULL,
`iduser` int(6) default NULL,
`type` tinyint(1) NOT NULL default '0',
`subject` varchar(200) NOT NULL default '',
`text` text NOT NULL,
`date` datetime default NULL,
PRIMARY KEY (`idpost`)
) TYPE=MyISAM COMMENT='Post for Topics';
Foro:
CREATE TABLE `foros` (
`idforo` int(6) unsigned NOT NULL auto_increment,
`idcat` int(6) default NULL,
`title` varchar(50) NOT NULL default '',
`description` varchar(255) NOT NULL default '',
`presentation_order` tinyint(2) default NULL,
`active` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`idforo`)
) TYPE=MyISAM COMMENT='Foros';
CREATE TABLE `post` (
`idpost` int(6) unsigned NOT NULL auto_increment,
`idtopic` int(6) default NULL,
`idforo` int(6) default NULL,
`iduser` int(6) default NULL,
`type` tinyint(1) NOT NULL default '0',
`subject` varchar(200) NOT NULL default '',
`text` text NOT NULL,
`date` datetime default NULL,
PRIMARY KEY (`idpost`)
) TYPE=MyISAM COMMENT='Post for Topics';
Foro:
CREATE TABLE `foros` (
`idforo` int(6) unsigned NOT NULL auto_increment,
`idcat` int(6) default NULL,
`title` varchar(50) NOT NULL default '',
`description` varchar(255) NOT NULL default '',
`presentation_order` tinyint(2) default NULL,
`active` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`idforo`)
) TYPE=MyISAM COMMENT='Foros';
Código PHP:
$query = "SELECT f.*,COUNT(p.idpost) AS themes FROM foros f, post p WHERE f.idforo=p.idforo AND f.idcat='".$idcat."' AND f.active<>0 GROUP BY (p.idforo) ORDER BY f.idforo";
Salu2