2
Can someone give us a little help, please? When I press on a blog post, I should just show that post on another page. But I’m not being able to show this post. For everyone I open, it’s always showing the same information and the same photo.
index php.
<?php require_once('conn.php');
$consulta_categoria = mysql_query("SELECT Posts.titulo_principal,
Posts.data,
Posts.descricao,
Categorias.categoria,
Posts.texto_inicial,
Posts.texto_secundario,
Posts.titulo_principal,
Posts.imagem1,
Posts.imagem1_dir,
Posts.imagem2,
Posts.imagem2_dir
FROM Posts
INNER JOIN Categorias ON Categorias.id = Posts.categoria_id ORDER BY Posts.id DESC");
$linha_categoria = mysql_fetch_assoc($consulta_categoria);
$consulta_menu = "SELECT id, categoria FROM categorias order by categoria asc";
$resultado_menu = mysql_query($consulta_menu, $conn) or die(mysql_error());
$linhas_menu = mysql_fetch_assoc($resultado_menu);
$consulta = "SELECT * FROM posts ORDER BY id DESC";
$resultado = mysql_query($consulta, $conn) or die(mysqli_error());
$linhas = mysql_fetch_assoc($resultado);
$consulta_recentes = "SELECT * FROM posts ORDER BY id DESC LIMIT 3";
$resultado_recentes = mysql_query($consulta_recentes, $conn) or die(mysqli_error());
$linhas_recentes = mysql_fetch_assoc($resultado_recentes);
?>
<div class="blog-post">
<?php do { ?>
<div class="post-thumb">
<a href="#"><img src="Admin/app/webroot/files/post/imagem1/<?php echo $linha_categoria['imagem1_dir']; ?>/<?php echo $linha_categoria['imagem1']; ?>"></a>
<div class="hover-wrap">
</div>
</div>
<div class="post-content">
<h6 class="post-title"><a href="post-detalhe.php?idpost=<?php echo $linhas['id'] ?>"><?php echo utf8_encode($linha_categoria['titulo_principal']); ?></a></h6>
<div class="meta">
<span class="meta-part"><a href="#"><i class="fas fa-align-justify"></i></i><?php echo utf8_encode($linha_categoria['categoria']); ?></a></span>
<span class="meta-part"><a href="#"><i class="fas fa-clock"></i> <?php echo utf8_encode($linha_categoria['data']); ?></a></span>
</div>
<p><?php echo utf8_encode($linha_categoria['descricao']); ?></p></p>
<a href="post-detalhe.php?idpost=<?php echo $linhas['id'] ?>" class="btn btn-common btn-rm">Leia Mais</a>
</div>
<?php } while ($linha_categoria = mysql_fetch_assoc($consulta_categoria)); ?>
</div>
post-detail.php
<?php require_once('conn.php');
$id = (int)$_GET['idpost'];
$resultado_post = mysql_query('SELECT * FROM posts WHERE id = ' . $id, $conn);
$linhas_post = mysql_fetch_assoc($resultado_post);
$consulta_menu = "SELECT id, categoria FROM categorias order by categoria asc";
$resultado_menu = mysql_query($consulta_menu, $conn) or die(mysql_error());
$linhas_menu = mysql_fetch_assoc($resultado_menu);
?>
Below is the code where it shows the post information, on the post-detail page.php:
<div class="col-lg-8 col-md-12 col-xs-12">
<div class="blog-post single-post">
<div class="post-thumb">
<a href="#"><img src="Admin/app/webroot/files/post/imagem1/<?php echo $linhas_post['imagem1_dir']; ?>/<?php echo $linhas_post['imagem1']; ?>"></a>
<div class="hover-wrap">
</div>
</div>
<div class="post-content">
<h4 class="post-title"><a href="#"><?php echo utf8_encode($linhas_post['titulo_principal']); ?></a></h4>
<div class="meta">
<span class="meta-part"><a href="#"><i class="fas fa-align-justify"></i> <?php echo $linhas_post['categoria']; ?></a></span>
<span class="meta-part"><a href="#"><i class="fas fa-clock"></i> <?php echo utf8_encode($linhas_post['data']); ?></a></span>
</div>
<p><?php echo utf8_encode($linhas_post['texto_inicial']); ?></p>
<br>
<div class="row">
<div class="col-sm-12">
<img src="Admin/app/webroot/files/post/imagem2/<?php echo $linhas_post['imagem2_dir']; ?>/<?php echo $linhas_post['imagem2']; ?>">
</div>
</div>
<br>
<p><?php echo utf8_encode($linhas_post['texto_secundario']); ?></p>
</div>
</div>
</div>
My code must be wrong, but I don’t know where I’m going wrong. Someone to help? Thank you!
For these codes, there seems to be no problem. Is the id number really changing in each record? See if every time you click on a post in "read more" the id is changed in the url.
– Andrei Coelho
Hi Andrei, I just saw here and the id is not changing. It is always repeating the same id, IE, is repeating the last id registered in the database. How do I show the right id and the post of that id?
– Márcia Prates
Put the code you generate that list there in the question. I see if I find anything...
– Andrei Coelho
There in the index file there is only one part of the code... the problem is there...
– Andrei Coelho
Okay, I think that’s it. I changed the index.php
– Márcia Prates
Is there the answer!
– Andrei Coelho