Código PHP:
function Foro(){
if(isset($_GET['foro']) && $_GET['foro']=="all"){
$query = "SELECT cf.* FROM catforos cf WHERE cf.active<>0 ORDER BY cf.presentation_order ASC";
$result = mysql_query($query) or die("No se ha podido ejecutar la consulta ".$query.". Error: ".mysql_error());
if(mysql_num_rows($result)!=0){
echo "<table width='100%' border='0' cellpadding='0' cellspacing='1' bordercolor='#003366' class='table'>
<tr><td width='62%' class='forotema' style='padding-left:5px; padding-right:3px; padding-top:2px; padding-bottom:2px;'>Foro</td>
<td width='11%' class='forotema center'>Mensajes</td><td width='8%' class='center forotema'>Temas</td>
<td width='19%' class='center forotema'>Último mensaje </td></tr>";
while($fetch=mysql_fetch_assoc($result)){
echo "<tr>
<td colspan='4' class='txt forotema' style='padding-left:5px; padding-right:3px; padding-top:2px; padding-bottom:2px;'>".$fetch['title']."</td>
</tr><tr><td colspan='4' class='txt'>";
# Llamada a la función para mostrar los Foros
Topics($fetch['idcat']);
echo "</td></tr>";
}
echo "<tr><td colspan='5' class='center forobottom' style='padding-left:5px; padding-right:3px; padding-top:2px; padding-bottom:2px;'>Foro diseñado por <a href='http://reynierpm.variosweb.com/index.php?action=show&".SID."'>ReynierPM Online</a> - © Todos los derechos reservados </td></tr>
<tr><td colspan='5' class='center forobottom' style='padding-left:5px; padding-right:3px; padding-top:2px; padding-bottom:2px;'>Versión 1.0.0a :: Acerca de ReynierPM Online Foro</td></tr>
</table>";
}else{
echo "No hay categorías disponibles en el Forum para mostrar";
}
}else{
# Llamada a la función para mostrar los Post
Post($_GET['foro']);
}
}
# Mod: Mostrar subforos
function Topics($idcat){
if(isset($_GET['foro']) && $_GET['foro']=="all"){
$query = "SELECT fr.* FROM foros fr WHERE fr.idcat='".$idcat."' AND fr.active<>0 ORDER BY fr.idforo";
$result = mysql_query($query) or die("No se ha podido ejecutar la consulta ".$query.". Error: ".mysql_error());
if(mysql_num_rows($result)!=0){
echo "<table width='100%' border='0' cellpadding='0' cellspacing='1' bordercolor='#003366'>";
while($fetch=mysql_fetch_assoc($result)){
# Consulta para calcular la cantidad de post
$sub_query = "SELECT idpost,count(idpost) as cant,date, DAYOFMONTH(date) AS dia, DAYOFWEEK(date) AS semana, MONTH(date) AS mes, YEAR(date) AS year, DATE_FORMAT(date,'%h:%i %p') AS hora FROM post WHERE idforo='".$fetch['idforo']."' AND idcat='".$idcat."' group by idcat ORDER BY date ASC";
$sub_result = mysql_query($sub_query) or die("No se ha podido ejecutar la consulta ".$sub_query.". Error: ".mysql_error());
$res = mysql_fetch_assoc($sub_result);
# Consulta para calculara la cantidad de mensajes
$sub_sub_query = "SELECT count(idreply) as cant FROM reply WHERE idforo='".$fetch['idforo']."' AND idcat='".$idcat."' AND idpost='".$res['idpost']."'";
$sub_sub_result = mysql_query($sub_sub_query) or die("No se ha podido ejecutar la consulta ".$sub_sub_query.". Error: ".mysql_error());
$res_res = mysql_fetch_assoc($sub_sub_result);
# Fecha del último post
if($res['date']==""){
$lastpost = "No hay nigún mensaje";
}else{
$nombre_meses = array("Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic");
$dias_semana = array("Dom","Lun","Mar","Mie","Jue","Vie","Sab");
$lastpost = $dias_semana[$res['semana']-1]." ".$res['dia']." ".$nombre_meses[$res['mes']-1]." ".$res['year']." ".$res['hora'];
}
# Obtenemos la cantidad de temas disponibles para ese Post, Foro y Categoria
if(mysql_num_rows($sub_sub_result)){
$themes = $res_res['cant'] + $res['idpost'];
}else{
$themes = 0;
}
# Obtenemos el numero de mensajes disponibles en ese foro y categoria
if(mysql_num_rows($sub_result)!=0){
$post = $res['cant'];
}else{
$post = 0;
}
echo "<tr><td width='2%' rowspan='2' class='txt td' style='padding-left:5px; padding-right:3px; padding-top:2px; padding-bottom:2px;'><div align='center'><a href='foros.php?action=show&catforo=".$fetch['idcat']."&foro=".$fetch['idforo']."&".SID."'><img src='images/forum/oldtopics.gif' width='27' height='27' border='0' alt='Entrar al Foro ".$fetch['title']."'></a></div></td>
<td width='57%' class='titleforo td' style='padding-left:5px; padding-right:3px; padding-top:2px; padding-bottom:2px;'><a href='foros.php?action=show&catforo=".$fetch['idcat']."&foro=".$fetch['idforo']."&".SID."'>".$fetch['title']."</a></td>
<td width='12%' class='txtcn td'>".$post."</td><td width='79' class='txtcn td'>".$themes."</td>
<td width='19%' class='txtcn td'>".$lastpost."</td></tr><tr>
<td colspan='4' class='txt td' style='padding-left:5px; padding-right:3px; padding-top:2px; padding-bottom:2px;'>".$fetch['description']."</td>
</tr>";
}
echo "</table>";
}else{
echo "Esta categoría no posee ningún Foro de Discusión";
}
}
}
El diseño de la BDatos es este:
Cita:
Salu2 CREATE TABLE `catforos` (
`idcat` int(6) unsigned NOT NULL auto_increment,
`title` varchar(50) NOT NULL default '',
`description` varchar(255) NOT NULL default '',
`presentation_order` bigint(2) default NULL,
`active` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`idcat`)
) TYPE=MyISAM COMMENT='Foros Categories';
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,
`idcat` 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';
CREATE TABLE `reply` (
`idreply` int(6) unsigned NOT NULL auto_increment,
`idpost` int(6) default NULL,
`idcat` int(6) default NULL,
`idforo` int(6) default NULL,
`iduser` int(6) default NULL,
`subject` varchar(50) NOT NULL default '',
`text` text NOT NULL,
`date` datetime default NULL,
PRIMARY KEY (`idreply`)
) TYPE=MyISAM COMMENT='Replies for Post';
`idcat` int(6) unsigned NOT NULL auto_increment,
`title` varchar(50) NOT NULL default '',
`description` varchar(255) NOT NULL default '',
`presentation_order` bigint(2) default NULL,
`active` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`idcat`)
) TYPE=MyISAM COMMENT='Foros Categories';
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,
`idcat` 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';
CREATE TABLE `reply` (
`idreply` int(6) unsigned NOT NULL auto_increment,
`idpost` int(6) default NULL,
`idcat` int(6) default NULL,
`idforo` int(6) default NULL,
`iduser` int(6) default NULL,
`subject` varchar(50) NOT NULL default '',
`text` text NOT NULL,
`date` datetime default NULL,
PRIMARY KEY (`idreply`)
) TYPE=MyISAM COMMENT='Replies for Post';