I'm new to php and mysql programming and new to this forum.
I want to know, if it is possible to select 1 specific image of a post to display. The posts are looking something like that:
+-------------------------+
| Post1: Title1...........|
| img1.......................|
| img2.......................|
| img3.......................|
+-------------------------+
+-------------------------+
| Post2: Title2...........|
| img4.......................|
| img5.......................|
| img6.......................|
+-------------------------+
How do I select for example "img3" of "Post1"?
I have 2 tables for many-to-one relationship:
CREATE TABLE posts (<br>
id_post int(11) not null AUTO_INCREMENT PRIMARY KEY,<br>
post_title varchar(100),<br>
post_descr varchar(100)<br>
);
CREATE TABLE images (<br>
id_img int(11) not null AUTO_INCREMENT PRIMARY KEY,<br>
img_file varchar(100),<br>
img_title text(100),<br>
post_id int(11) not null REFERENCES posts(id_post)<br>
);
and this is how I display all images of a post:
$resultx = mysqli_query($db, "SELECT img_file, img_title FROM images WHERE post_id = " .$rowx['id_post']);
if(mysqli_num_rows($resultx) > 0) {
while ($rowx = mysqli_fetch_array($resultx)) {
echo "<img src='../folder_image_uploads/".$rowx['img_file']."' >";
echo $rowx['img_title'];
}
}
and it works perfectly for what it should do, but again:
How do I select "img3" of "Post1" to echo it?
Is it even possible in my example?