0
I have the two tables below
table IMAGES
id_imagens | diretorio_imagem | post_id
1 imagem1.jpg 1
2 imagem2.jpg 1
3 imagem3.jpg 1
4 imagem4.jpg 1
5 imagem5.jpg 2
6 imagem6.jpg 2
7 imagem7.jpg 2
8 imagem8.jpg 2
Table POSTS
id_post | slug | titulo
1 titulo_do_post Titulo do Post
2 titulo_do_post_2 Titulo do Post 2
PHP:
$slug = $_GET['slug'];
$stmt = $db->prepare("SELECT * FROM posts, imagens
WHERE posts.id_post = imagens.post_id
AND slug=:slug");
$stmt->execute(array(":slug"=>$_GET['slug']));
while($row=$stmt->fetch(PDO::FETCH_BOTH))
{
?>
<h3>Você esta aqui:<?php print utf8_encode($row['titulo']);?></h3>
<!-- Start Anuncio-->
<div>
<img src="http://entreconnection.com/wp-content/uploads/2012/09/Wide-Skyscrapper3.png" style="margin-top:50px;">
</div>
<!--End Anuncio-->
<h1><?php print utf8_encode($row['titulo']);?></h1>
<img src="<?php print ($row['diretorio_imagem']); ?>">
<div>
<!-- Start Anuncio-->
<div style="text-align:center">
<img src="https://www.google.com/help/hc/images/adsense/mobile-leaderboard.png" style="margin:20px;">
</div>
<!-- END Anuncio -->
<div class="fb-comments" data-href="<?php echo BASE_URL ?>/<?php print ($row['slug']); ?>" data-width="600" data-numposts="5"></div>
</div>
<?php
}
?>
By going to the "Post title 2" page:
Titulo do post 2
imagem5.jpg
Titulo do post 2
imagem6.jpg
Titulo do post 2
imagem7.jpg
Titulo do post 2
imagem8.jpg
How to have the result:
Titulo do post 2
imagem5.jpg
imagem6.jpg
imagem7.jpg
imagem8.jpg
I already understood that you can have an if check or make a group by in sql statement, but it is not entering in my head how to make the check if the title already exists before printing... or if to use group by how to foreach the images inside while
I appreciate help
thanks resolves to print the title only once, but in the other contents (advertisements and html tags) inside while continue to be duplicated according to the amount of images, it is impossible to create several ifs
– Gisele
The solution you wanted is solved, I’m not understanding what you want now, advertisements? Explain better what you want.
– Mastria
I marked it as settled, because it really settles the question thank you very much. As I commented there are other html contents inside while and in some parts there are php tags in the case of the title and images, with its solution the title prints a single time but the rest of the html content is replicated according to the amount of images
– Gisele
What else? Post what is coming out and what is waiting to come out to try to find a solution.
– Mastria
In the question I entered some information inside the while for you to have an idea
– Gisele
I edited the answer, see if it works
– Mastria