Jump to content


Ali3n

Member Since 08/01/2004
Offline Last Active 08/01/2012, 10:02
-----

Topics I've Started

Duvida Em Busca No Banco De Dados

06/05/2009, 22:26

Salve galera..... To meio perdido aqui na coisa e nao to conseguindo me axar....

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>
<? } ?>

Paginação Em Um Sistema De Video Que Le Diretorios

08/01/2009, 12:11

Galera to meio perdido aqui necessitando de ideias.....

Tenho o seguinte código que faz a leitura de arquivos gravados em um diretório e mostra os vídeos cadastrados nele.... através do youtube tava pensando no mesmo fazer uma paginação de 5 em 5 vídeos algo assim pra pagina não ficar muito grande e futuramente poder cadastrar os vídeos por categorias....

Segue o Código.

[codebox]<?

echo '<link href="estilo.css" rel="stylesheet" type="text/css">';

$nomepasta = arqs . "/";

$pasta = opendir($nomepasta);

$arquivos = array();

$i = 0;

echo"<table width=100% border=0 cellspacing=0 cellpadding=0>";

while ($arquivo = readdir($pasta)) {

$caminho = $nomepasta.$arquivo;

if (is_file($caminho)) {

$data_modificacao = $caminho.$arquivo;
$arquivos[$data_modificacao] = $arquivo;

}

}

krsort($arquivos);


foreach ($arquivos as $arquivo) {

include("arqs/$arquivo");

echo "<td align=center valign=bottom>
<object width='425' height='344'><param name='movie' value='http://www.youtube.com/v/$video"."s&hl=pt-br&fs=1'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/$video"."&hl=pt-br&fs=1' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='425' height='344'></embed></object><br><br> $coment<br><br><br><br>";

$i = $i + 1;

if ($i == "1")
{ $i = 0; echo"</tr><tr>"; }
}
echo"</td></table>";
?>
[/codebox]

IPB Skin By Virteq