Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd image according to 4 returned records in php
    text
    copied!<p>I need to add an image (saved path in mysql - image from file on server) to my page according to 4 rows returned. There will always be 4 rows returned from db.</p> <p>My problem is that it shows the same image (main with 3 thumbnails) in all 4 image holders. I've used the following to add the images ...</p> <p>First my php function -</p> <pre><code>//Get all images within a specific album... function get_images($vehicleid) { //$vehicle_id = (int)$vehicle_id; $images = array(); $image_query = mysql_query("SELECT * FROM `images` WHERE `images`.`vehicle_id`='$vehicleid'"); $result = $image_query; if (!$result){ echo 'Error in loading vehicle adverts. Please refresh page and try again'; exit(); } while($images_row = mysql_fetch_assoc($image_query)) { $images[] = array( 'imageid' =&gt; $images_row['image_id'], 'branch' =&gt; $images_row['branch'], 'vehicleid' =&gt; $images_row['vehicle_id'], 'timestamp' =&gt; $images_row['timestamp'], 'ext' =&gt; $images_row['ext'], 'imagenum' =&gt; $images_row['imagenum'] ); //This returns main image and 3 thumbs, but only image from first record is returned.. return $images; } //return $images; //When runned from here, main image is from 1st, then 2nd, 3rd etc row returned, but it loads each rows image as a main and the thumbs the same image... } </code></pre> <p>The code I have used to load the images is as follow ...</p> <pre><code>&lt;?php //Get images... $images = get_images($vehicleid); if (empty($images)) { ?&gt; &lt;table id="thumbnails"&gt; &lt;tr&gt; &lt;td&gt; &lt;div&gt; &lt;a href="testdrive.php" style="text-decoration:none"&gt;&lt;img src="uploads/noimage.jpg" width="600px" height="400px" title="Sorry, No Image Available Yet" /&gt;&lt;/a&gt; &lt;/div&gt; &lt;/td&gt; &lt;td&gt; &lt;table width="350px"&gt; &lt;tr height="50px"&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;div id="mainimages" align="center" style="font-size:14px"&gt; &lt;?php echo $year, ' ', $manufacturer, ' ', $modelrange, ' ', $modelder, '.', '&lt;br /&gt;', '&lt;br /&gt;', 'This beautiful ', $colour, ' ',$manufacturer, ' only has ', $mileage, ' kilometres with a service history and is selling for ', '&lt;strong&gt;ONLY R ', $price, '. &lt;/strong&gt;', '&lt;br /&gt;', '&lt;br /&gt;', 'It features ', $comments, '&lt;br /&gt;', '&lt;br /&gt;', 'This vehicle is available NOW from our ', '&lt;a href="testdrive.php" style="text-decoration:none"&gt;', 'Tata - ', $branch, ' branch.&lt;/a&gt;'; ?&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;div id="mainimages" align="center" style="font-size:14px"&gt; &lt;?php //MAIN IMAGE HERE FROM RECORD 1 (Note from upload folder, not thumbs as below)... echo '&lt;a href="delete_image.php?vehicle_id='.$vehicleid.'"&gt;&lt;img src="images/delete.png" title="Delete Advert" /&gt;&lt;/a&gt;'; ?&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;img src="uploads/thumbs/noimage.jpg" title="Sorry, No Image Available Yet" width="100px" height="100px" /&gt;&lt;img src="uploads/thumbs/noimage.jpg" title="Sorry, No Image Available Yet" width="100px" height="100px" /&gt;&lt;img src="uploads/thumbs/noimage.jpg" title="Sorry, No Image Available Yet" width="100px" height="100px" /&gt; &lt;p style="height:10px"&gt;&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?php //echo '&lt;img src="uploads/noimage.jpg" /&gt;'; } else { //Display images thumbs... foreach ($images as $image) { ?&gt; &lt;table id="thumbnails"&gt; &lt;tr&gt; &lt;td&gt; &lt;?php //Add image title to the right of main image... echo '&lt;a href="testdrive.php" style="text-decoration:none"&gt;&lt;img src="uploads/', $image['vehicleid'], '/', $image['imageid'], '.', $image['ext'], '" title="Uploaded ', date('D M Y / h:i', $image['timestamp']), ' - ', $year, ' ', $manufacturer, ' ', $modelrange, ' ', $modelder, '.', 'This beautiful ', $colour, ' ',$manufacturer, ' only has ', $mileage, ' kilometres and is selling for ', 'ONLY R ', $price, '.', '" width="600px" height="400px" /&gt;&lt;/a&gt;'; ?&gt; &lt;/div&gt; &lt;/td&gt; &lt;td&gt; &lt;table width="350px"&gt; &lt;tr height="50px"&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;div id="mainimages" align="center" style="font-size:14px"&gt; &lt;?php echo $year, ' ', $manufacturer, ' ', $modelrange, ' ', $modelder, '.', '&lt;br /&gt;', '&lt;br /&gt;', 'This beautiful ', $colour, ' ',$manufacturer, ' only has ', $mileage, ' kilometres with a service history and is selling for ', '&lt;strong&gt;ONLY R ', $price, '. &lt;/strong&gt;', '&lt;br /&gt;', '&lt;br /&gt;', 'It features ', $comments, '&lt;br /&gt;', '&lt;br /&gt;', 'This vehicle is available NOW from our ', '&lt;a href="testdrive.php" style="text-decoration:none"&gt;', 'Tata - ', $branch, ' branch.&lt;/a&gt;'; ?&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;div id="mainimages" align="center" style="font-size:14px"&gt; &lt;?php echo '&lt;a href="delete_image.php?vehicle_id='.$vehicleid.'"&gt;&lt;img src="images/delete.png" title="Delete Advert" /&gt;&lt;/a&gt;'; ?&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;?php //THIS WHERE I NEED TO START LOADING THE CORRECT IMAGES - THIS SHOULD BE IMAGE RETURNED FROM RECORD 2... echo '&lt;a href="testdrive.php" style="text-decoration:none"&gt;&lt;img src="uploads/thumbs/', $image['vehicleid'], '/', $image['imageid'], '.', $image['ext'], '" title="Uploaded ', date('D M Y / h:i', $image['timestamp']), ' - ', $year, ' ', $manufacturer, ' ', $modelrange, ' ', $modelder, '.', 'This beautiful ', $colour, ' ',$manufacturer, ' only has ', $mileage, ' kilometres and is selling for ', 'ONLY R ', $price, '.', '" onclick="showImage("uploads/', $image['vehicleid'], '/', $image['imageid'], '.', $image['ext'], '" width="100px" height="100px")" /&gt;&lt;/a&gt;'; //THIS SHOULD BE IMAGE RETURNED FROM RECORD 3... echo '&lt;a href="testdrive.php" style="text-decoration:none"&gt;&lt;img src="uploads/thumbs/', $image['vehicleid'], '/', $image['imageid'], '.', $image['ext'], '" title="Uploaded ', date('D M Y / h:i', $image['timestamp']), ' - ', $year, ' ', $manufacturer, ' ', $modelrange, ' ', $modelder, '.', 'This beautiful ', $colour, ' ',$manufacturer, ' only has ', $mileage, ' kilometres and is selling for ', 'ONLY R ', $price, '.', '" onclick="showImage("uploads/', $image['vehicleid'], '/', $image['imageid'], '.', $image['ext'], '" width="100px" height="100px")" /&gt;&lt;/a&gt;'; //THIS SHOULD BE IMAGE RETURNED FROM RECORD 4... echo '&lt;a href="testdrive.php" style="text-decoration:none"&gt;&lt;img src="uploads/thumbs/', $image['vehicleid'], '/', $image['imageid'], '.', $image['ext'], '" title="Uploaded ', date('D M Y / h:i', $image['timestamp']), ' - ', $year, ' ', $manufacturer, ' ', $modelrange, ' ', $modelder, '.', 'This beautiful ', $colour, ' ',$manufacturer, ' only has ', $mileage, ' kilometres and is selling for ', 'ONLY R ', $price, '.', '" onclick="showImage("uploads/', $image['vehicleid'], '/', $image['imageid'], '.', $image['ext'], '" width="100px" height="100px")" /&gt;&lt;/a&gt;'; ?&gt; &lt;p style="height:10px"&gt;&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?php } } } ?&gt; </code></pre> <p>Anyone have any idea how I can return the correct images to their respective html holders?</p> <p>Thanx guys.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload