Preciso listar todas as noticias cadastradas no banco de dados porem estas devem ser separadas por categorias e so estou conseguindo listar todas. Abaixo segue o codigo e parte da tabela.
No mais obrigado.
-- -- Estrutura da tabela `noticias_categorias` CREATE TABLE `noticias_categorias` ( `id` int(3) NOT NULL auto_increment, `nome` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=2; -- Extraindo dados da tabela `noticias_categorias` INSERT INTO `noticias_categorias` VALUES (1, 'Geral'); -- Estrutura da tabela `noticias_dados` CREATE TABLE `noticias_dados` ( `id` int(5) NOT NULL auto_increment, `idcat` char(3) NOT NULL default '', `nome` varchar(30) NOT NULL default '', `email` varchar(80) default NULL, `data` varchar(10) NOT NULL default '', `titulo` text NOT NULL, `subtitulo` text, `texto` text NOT NULL, `foto01` varchar(50) default NULL, `fotos_extras` char(3) NOT NULL default 'nao', `alinhamento_foto` varchar(5) NOT NULL default 'left', `borda` char(3) NOT NULL default '', `creditos_foto` varchar(255) NOT NULL default '', `destaque` char(3) NOT NULL default 'nao', `largura_foto` char(3) NOT NULL default '405', `altura_foto` char(3) NOT NULL default '', PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) TYPE=MyISAM AUTO_INCREMENT=2;
abaixo codigo que lista todas elas
<? include("config.php"); $pg=$_GET[pg]; $page=$_GET[page]; $busca = "SELECT * FROM noticias_dados order by id desc"; if($idcat == "1"){ $palavra = "Notícias"; } else { $palavra = "Notícias"; } $total_reg = "$qts_ultimos"; if(!$page){ $page = "1"; } $inicio = $page-1; $inicio = $inicio*$total_reg; $limite = mysql_query("$busca LIMIT $inicio,$total_reg"); $todos = mysql_query("$busca"); $tr = mysql_num_rows($todos); $tp = ceil($tr / $total_reg); if(mysql_num_rows($todos)>0){ ?> <table width="100%" cellpadding="0" cellspacing="0"> <tr> </tr> <? while ($dados=mysql_fetch_array($limite)) {?> <TR> <TD height="18" align='left' valign="middle"><a href="?pg=48&id=<?=$dados[id]?>"> <? echo "<strong>$dados[titulo]</strong>";?></a></span></Td> </TR> <tr> <td height="5" colspan="2"></td> </tr> <tr> <td height="1" colspan="2">x</td> </tr> <tr> <td height="5" colspan="2"></td> </tr> <? }?> <tr> <TD><table border="0" align="center" cellpadding="0" cellspacing="0"> <TR> <TD width="100" align="right" valign="top"><? if($page > 1){ $anterior = $page -1; $url = "?pg=$pg&page=$anterior"; echo "<a href='$url'>« Anterior</a> |"; } else { echo "<font color='$corcelula2'>« Anterior</font> |"; } ?></TD> <TD align="center"><? for($x=1; $x<=$tp; $x++){ $url = "?pg=$pg&page=$x"; if ($x==$page) { echo "<font color='$coronmouse'><b>$x</b></font>|"; } else { echo "<a href='$url'>$x</a>|"; } } ?></TD> <TD width="100" align="left" valign="top"><? if($tp > $page){ $proxima = $page +1; $url = "?pg=$pg&page=$proxima"; echo " <a href='$url'>Próxima »</a>"; } else { echo " <font color='$corcelula2'>Próxima »</font>"; } ?></TD> </TR> </table></TD> </tr> </table> <? } else {?> <BR> <table width="100%" cellpadding="0" cellspacing="0"> <TR> <TD align="center" valign="bottom"><br> Desculpe-nos, mas no momento não temos nenhuma noticia cadastrada em nosso banco de dados!<br> <br></td> </tr> </table> <? } ?>