0
Hello, 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
In the post.php page I search for the posts table Slug:
$slug = $_GET['slug'];
$stmt = $db->prepare("SELECT * FROM posts WHERE slug=:slug");
$stmt->execute(array(":slug"=>$_GET['slug']));
while($row=$stmt->fetch(PDO::FETCH_BOTH))
{
print utf8_encode($row['titulo']);
}
The above code takes the url’s Slug and searches the DB.
www.meusite.com.br/titulo_do_post_2
The php code above will take the titulo_do_post_2 snippet and search in DB something identical. So far ok, the next step is through Slug to find out what the id of the post and with the id of the post ai yes do an Inner Join
I would like by Slug to know the id_post and return from the table IMAGES that has the identical post_id to display all images
Gave bug don’t know how to do, Inner Join still have a lot of difficulty to use
I appreciate help
thanks @Cosmelopes but no error appears nor prints the information, simply goes blank
– Gisele
I edited the answer with an example of code, take a look.
– user28527
the title is being printed more often depending on the number of images, should print the title only once followed by the images
– Gisele
The idea is to show you how to get the data. Now you have all images related to the post. How you use the list in your application is up to you.
– user28527