Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Pessoal, tô com um problema aqui que não consigo resolver por nada. Tenho um banco de dados com uma tabela de nome NOTICIAS. Tenho uma página que exibe os títulos de todas as notícias cadastradas no banco de dados. Até aí tudo certinho. Só que gostaria que quando a pessoa clicasse em um título específico, abrisse outra página exibindo apenas a notícia que foi clicada.
Se alguém puder me ajudar, ficaria muito agradecido.
Desde já, agradeço a todos pela atenção.
Vou postar os códigos das bd e das minhas páginas:
Banco de dados:
CREATE TABLE noticias (
id int(10) NOT NULL auto_increment,
titulo varchar(50) NOT NULL default '0',
texto text NOT NULL,
data date default NULL,
hora time default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;
#
INSERT INTO noticias VALUES("1", "Notícia 1... testando...", "123 teste 1...", "2009-11-04", "16:51:33");
INSERT INTO noticias VALUES("2", "Notícia 2... testando...", "123 teste 2...", "2009-11-04", "23:58:44");
INSERT INTO noticias VALUES("3", "Notícia 3... testando...", "123 teste 3...", "2009-11-05", "00:18:21");
Página onde estão sendo exibidos os títulos das notícias:
<?
include("conecta.php");
$sql="select * from noticias order by data DESC, hora DESC";$porpag=5;
if (!isset($_GET["Pag"])){
$_GET["Pag"]=1;
}
$primeiro=($_GET["Pag"]*$porpag)-($porpag);
$sql="select *,date_format(data,\"%d/%m/%Y\") as data1 from noticias order by data DESC, hora DESC limit ".$primeiro.", ".$porpag;
$paginas=ceil($registros/$porpag);?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-image: url(../imagens/layout/noticias_espaco.jpg);
background-repeat: no-repeat;</style>
<link href="../css/estilo.css" rel="stylesheet" type="text/css">
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="148">
<!-- fwtable fwsrc="layout noticias 2.png" fwpage="Page 1" fwbase="layout_noticias.jpg" fwstyle="Dreamweaver" fwdocid = "1462996858" fwnested="0" -->
<tr>
<td><img src="../imagens/layout_noticias/spacer.gif" width="17" height="1" border="0" alt="" /></td>
<td><img src="../imagens/layout_noticias/spacer.gif" width="114" height="1" border="0" alt="" /></td>
<td><img src="../imagens/layout_noticias/spacer.gif" width="17" height="1" border="0" alt="" /></td>
<td><img src="../imagens/layout_noticias/spacer.gif" width="1" height="1" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="3" align="center" valign="top">
<!--começa aqui o loop-->
<?php while($dados=mysql_fetch_assoc($resultado)){ //associa dados com resultado ?>
<table width="134" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" class="noticias"><b><? echo $dados["data1"]; ?></b> - <?php echo $dados["titulo"];?> <a href="admin/noticias_ler.php?id=<?php echo $dados["id"];?>" target="centro">lerr</a></td>
</tr>
</table>
<table width="134" height="10" border="0" cellpadding="0" cellspacing="0">
<tr class="textoformulario">
<td align="center" class="textoformulario"> </td>
</tr>
</table>
<?php } ?>
<!--fim do while (loop)...-->
</td>
<td><img src="../imagens/layout_noticias/spacer.gif" width="1" height="323" border="0" alt="" /></td>
</tr>
<tr>
<td>
<? if ($_GET["Pag"]>1) { ?>
<a href="noticias.php?Pag=<? echo $_GET["Pag"]-1; ?>">
<img name="voltar" src="../imagens/layout_noticias/voltar.jpg" width="17" height="17" border="0" id="voltar" alt="" /></a>
<? } ?>
</td>
<td> </td>
<td>
<? if($_GET["Pag"]<$paginas){ ?>
<a href="noticias.php?Pag=<? echo $_GET["Pag"]+1; ?>"><img name="avancar" src="../imagens/layout_noticias/avancar.jpg" width="17" height="17" border="0" id="avancar" alt="" /></a>
<? } ?>
</td>
<td><img src="../imagens/layout_noticias/spacer.gif" width="1" height="17" border="0" alt="" /></td>
</tr>
</table>
</body>
</html>
Página onde quero que a notícia que foi clicada apareça:
<?php
require_once("conecta.php");
if(isset($_GET["id"])){
$sql = "select * from noticias where id=".$_GET["id"];
$resultado = mysql_query($sql, $conexao) or die(mysql_error());
$dados = mysql_fetch_assoc($resultado);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<br />
Título:<?php echo $dados["titulos"]; ?>
<br />
Texto:<?php echo $dados["texto"]; ?>
</body>
</html>>
Você quer que assim que acontecer o clique o que se refere ao que foi clicado apareça em uma outra pagina?? é isso mesmo??
Exatamente isso meu amigo. Tem como dar uma força?
Acho que tô errando alguma coisa nesse id.
tenta assim amigo..
<?php
include("conecta.php");
$id = $_GET["id"];
$sql = "SELECT * FROM noticias WHERE `id` = '$id'";
$limite = mysql_query("$sql");
while ($sql = mysql_fetch_array($limite) ) {
$titulo = $sql["titulo"];
$texto = $sql["texto"];
$data = $sql["data"];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Notícias</title>
</head>
<body>
<br />
Título:<?php echo $titulo; ?>
<br />
Texto:<?php echo $texto; ?>
<br />
Data: <?php echo $data; ?>
</body>
</html>>
tenta assim amigo..
<?php
include("conecta.php");
$id = $_GET["id"];
$sql = "SELECT * FROM noticias WHERE `id` = '$id'";
$limite = mysql_query("$sql");
while ($sql = mysql_fetch_array($limite) ) {
$titulo = $sql["titulo"];
$texto = $sql["texto"];
$data = $sql["data"];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Notícias</title>
</head>
<body>
<br />
Título:<?php echo $titulo; ?>
<br />
Texto:<?php echo $texto; ?>
<br />
Data: <?php echo $data; ?>
</body>
</html>
Deu certinho Ewerton. Brigadão mesmo meu amigo. Sua ajuda foi de grande importância. Me salvou aqui.
Precisando de alguma coisa, pode contar comigo.
Abração.
Marco
exibe o sql na tela pra verificar se o $_get["id"] esta sendo capturado corretamente
if(isset($_GET["id"])){
$sql = "select * from noticias where id=".$_GET["id"];
echo $sql."<BR>";
$resultado = mysql_query($sql, $conexao) or die(mysql_error());
$dados = mysql_fetch_assoc($resultado);
}
dai você analisa o seu sql se estiver assim
select * from noticias where id=
é por que o id nao esta sendo repassado para a pagina.Tenta assim cara
<?php
$id = $_GET["id"];
$sql=mysql_query("SELECT * FROM noticias WHERE id= '$id'");
$pessoa=mysql_fetch_assoc($sql);
?>
Você quer que assim que acontecer o clique o que se refere ao que foi clicado apareça em uma outra pagina?? é isso mesmo??