Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8720535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:03:57+00:00 2026-06-13T07:03:57+00:00

I need to add an image (saved path in mysql – image from file

  • 0

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.

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 …

First my php function –

//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' => $images_row['image_id'],
            'branch' => $images_row['branch'],
            'vehicleid' => $images_row['vehicle_id'],
            'timestamp' => $images_row['timestamp'],
            'ext' => $images_row['ext'],
            'imagenum' => $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...
}

The code I have used to load the images is as follow …

<?php
    //Get images...
$images = get_images($vehicleid);

if (empty($images)) {
    ?>

    <table id="thumbnails">
        <tr>
            <td>                                        
                <div>
                <a href="testdrive.php" style="text-decoration:none"><img src="uploads/noimage.jpg" width="600px" height="400px" title="Sorry, No Image Available Yet" /></a>
                </div>                    
            </td>
            <td>
                <table width="350px">
                    <tr height="50px">
                    </tr>
                    <tr>
                        <td>
                            <div id="mainimages" align="center" style="font-size:14px">
                                <?php echo $year, ' ', $manufacturer, ' ', $modelrange, ' ', $modelder, '.', '<br />', '<br />', 'This beautiful ', $colour, ' ',$manufacturer, ' only has ', $mileage, ' kilometres  with a service history and is selling for ', '<strong>ONLY R ', $price, '. </strong>', '<br />', '<br />', 'It features ', $comments, '<br />', '<br />', 'This vehicle is available NOW from our ', '<a href="testdrive.php" style="text-decoration:none">', 'Tata - ', $branch, ' branch.</a>'; ?> 
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <div id="mainimages" align="center" style="font-size:14px">
                                 <?php //MAIN IMAGE HERE FROM RECORD 1 (Note from upload folder, not thumbs as below)...
                                 echo '<a href="delete_image.php?vehicle_id='.$vehicleid.'"><img src="images/delete.png" title="Delete Advert" /></a>'; 
                                 ?>
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
            </tr>
            <tr>
            <td>
                <img src="uploads/thumbs/noimage.jpg" title="Sorry, No Image Available Yet" width="100px" height="100px" /><img src="uploads/thumbs/noimage.jpg" title="Sorry, No Image Available Yet" width="100px" height="100px" /><img src="uploads/thumbs/noimage.jpg" title="Sorry, No Image Available Yet" width="100px" height="100px" />

                <p style="height:10px"></p>
            </td>
        </tr>
    </table>

    <?php
        //echo '<img src="uploads/noimage.jpg" />';
        } else {
            //Display images thumbs...
            foreach ($images as $image) {
    ?>

    <table id="thumbnails">
        <tr>
            <td>
                <?php 
                    //Add image title to the right of main image...
                    echo '<a href="testdrive.php" style="text-decoration:none"><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" /></a>'; 
                ?>
                </div>
            </td>
            <td>
                <table width="350px">
                    <tr height="50px">
                    </tr>
                    <tr>
                        <td>
                            <div id="mainimages" align="center" style="font-size:14px">
                                <?php 
                                echo $year, ' ', $manufacturer, ' ', $modelrange, ' ', $modelder, '.', '<br />', '<br />', 'This beautiful ', $colour, ' ',$manufacturer, ' only has ', $mileage, ' kilometres with a service history and is selling for ', '<strong>ONLY R ', $price, '. </strong>', '<br />', '<br />', 'It features ', $comments, '<br />', '<br />', 'This vehicle is available NOW from our ', '<a href="testdrive.php" style="text-decoration:none">', 'Tata - ', $branch, ' branch.</a>'; 
                                ?> 
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <div id="mainimages" align="center" style="font-size:14px">
                                 <?php
                                 echo '<a href="delete_image.php?vehicle_id='.$vehicleid.'"><img src="images/delete.png" title="Delete Advert" /></a>'; 
                                 ?>
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
            </tr>
            <tr>
            <td>
                <?php //THIS WHERE I NEED TO START LOADING THE CORRECT IMAGES - THIS SHOULD BE IMAGE RETURNED FROM RECORD 2...
                echo '<a href="testdrive.php" style="text-decoration:none"><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")" /></a>';

    //THIS SHOULD BE IMAGE RETURNED FROM RECORD 3...
                echo '<a href="testdrive.php" style="text-decoration:none"><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")" /></a>';

    //THIS SHOULD BE IMAGE RETURNED FROM RECORD 4...
                echo '<a href="testdrive.php" style="text-decoration:none"><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")" /></a>';
                ?>

                <p style="height:10px"></p>
            </td>
        </tr>
    </table>

    <?php
            }
        }
    }
   ?>

Anyone have any idea how I can return the correct images to their respective html holders?

Thanx guys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:03:58+00:00Added an answer on June 13, 2026 at 7:03 am

    My previous answer is not correct, but still valid because you never use “imagenum”. And return still must be outside the while.

    Anyway the reason you get always the same image is that you’re using always the same array element.

    Try:

    $i=0;
    foreach ($images as $image) {
        If($i=0) { 
    ?>
    
    <table id="thumbnails">
        <tr>
            <td>
                <?php 
                    //Add image title to the right of main image...
                    echo '<a href="testdrive.php" style="text-decoration:none"><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" /></a>'; 
                ?>
                </div>
            </td>
            <td>
                <table width="350px">
                    <tr height="50px">
                    </tr>
                    <tr>
                        <td>
                            <div id="mainimages" align="center" style="font-size:14px">
                                <?php 
                                echo $year, ' ', $manufacturer, ' ', $modelrange, ' ', $modelder, '.', '<br />', '<br />', 'This beautiful ', $colour, ' ',$manufacturer, ' only has ', $mileage, ' kilometres with a service history and is selling for ', '<strong>ONLY R ', $price, '. </strong>', '<br />', '<br />', 'It features ', $comments, '<br />', '<br />', 'This vehicle is available NOW from our ', '<a href="testdrive.php" style="text-decoration:none">', 'Tata - ', $branch, ' branch.</a>'; 
                                ?> 
                            </div>
                        </td>
                    </tr>
    
                    <tr>
                        <td>
                            <div id="mainimages" align="center" style="font-size:14px">
                                 <?php
                                 echo '<a href="delete_image.php?vehicle_id='.$vehicleid.'"><img src="images/delete.png" title="Delete Advert" /></a>'; 
                                 ?>
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
            </tr>
            <tr>
            <td>
                <?php $i=1; } else {//THIS WHERE I NEED TO START LOADING THE CORRECT IMAGES - THIS SHOULD BE IMAGE RETURNED FROM RECORD 2...
                echo '<a href="testdrive.php" style="text-decoration:none"><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")" /></a>';
    
                ?>
    
    
    
    <?php
            }
        }
    }
    ?>
                <p style="height:10px"></p>
            </td>
        </tr>
    </table>
    

    Or something similar (it’s difficult to write code in the stackoverflow editor).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to add text, image over video and save mixed file into another
I need to add an image/icon to the last column in the row. And
In One of my application i need to add some image in video. so
I need to know can we add image in TextArea through StyleableTextField htmlText because
I need allow registered front end users to add, remove images to image gallery.
I am using the Add-on builder and I need to receive binary data (image).
I need add Auto complete on apex Tabular Form. there is a column as
I have an ASHX handler returning an image on page load. I need to
I need add a new user group for mediawiki. The new group has more
I can't access a element with its href. Like this example, i need add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.