This Question Has Gotten Updated:
I have these columns stored in the table "thread":
id - title - caption - image_file_id - hashtag_id - date_created
An example for "image_file_id", it are the ID numbers of the "images" table for the image files:
583, 584, 585
The script should get the "title" and the "caption" from the "thread" table and print them with a while loop, then it also should get the image files from the "images" table and also print them corresponding to the thread ID.
E.g.
Thread ID: 35
<h1>Title</h1>
<p>Caption</p>
1. <img src=""/>
2. <img src=""/>
3. <img src=""/>
4. <img src=""/>
Thread ID: 36
<h1>Title</h1>
<p>Caption</p>
1. <img src=""/>
2. <img src=""/>
EDIT:
After the suggestion by "Steve" I have gotten it to work with this script here:
<!DOCTYPE html>
<html>
<head>
<title>
</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>
<body>
<?php
include("connect.php");
?>
<?php
$tqs = "SELECT * FROM `thread`";
$tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc));
// $row = mysqli_fetch_assoc($tqr);
// The ID numbers of the image files.
// This prints e.g.:
// Array ( [0] => 583 [1] => 584 [2] => 585 )
// print_r($exploded);
// echo "<br/><br/>";
//This prints e.g.:
// 3
// print_r(count($exploded));
// Select the image files by the ID numbers
// Iterate through he image files:
while ($row = mysqli_fetch_assoc($tqr)){
echo "<div class='content'>";
echo "<div class='title_caption'>";
echo "<h1>" . $row['title'] . "</h1>";
echo "<p>" . $row['caption'] . "</p>";
echo "</div>";
echo "<div class='parent-container'>";
// Have the image files printed on screen here!
$exploded = explode(", ", $row['image_file_id']);
foreach($exploded as $id){
$tqs_two = "SELECT `image_file` FROM `images` WHERE `id` = '" . $id . "'";
$tqr_two = mysqli_query($dbc, $tqs_two) or die(mysqli_error($dbc));
$row_two = mysqli_fetch_assoc($tqr_two);
echo "<img src='http://localhost/gallerysite/multiple_image_upload/thumbs/" . $row_two['image_file'] . "' />";
}
echo "</div>";
echo "</div>";
}
?>
</body>
</html>
I would like to ask if this script is correct, as said it is working.
This script goes row by row, though my question would be: how can I ensure that the image files are correctly printed on screen corresponding to the "thread ID"?