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 7615669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:41:58+00:00 2026-05-31T02:41:58+00:00

I am trying to do something easy I am sure but I have looked

  • 0

I am trying to do something easy I am sure but I have looked and tested and I am not doing something right.
I have a DB that stores the image file name, I need to get the file name based on the ID in the HTML , let me explain:

 <div class="slide">
                    <div class="image-holder">
                       <img src="img/asoft_table.jpg" alt="" /> 
                    </div>
                    <div class="info">

                        <p>Morbi a tellus lorem, id scelerisque ligula. Maecenas vitae turpis et.</p>
                    </div>
                </div>
                <div class="slide">
                    <div class="image-holder">
                        <img src="img/soft_table.jpg" alt="" />
                    </div>
                    <div class="info">

                        <p>Sed semper, lorem ac lobortis bibendum, magna neque varius augue, vel accumsan.</p>
                    </div>
                </div>
                <div class="slide">
                    <div class="image-holder">
                        <img src="img/living_room2.jpg" alt="" />
                    </div>

in each instance of an img tag, I need to insert the filename from the DB. so, first image tag would be primary key 1, second primary key 2 and so forth.
Here is the PHP script I am using to retrieve the filename, which works, but I am unsure how to send the ID of the image to the script and then return it properly.

 <?php
 $hote = 'localhost';
 $base = '*****';
 $user = '*****';
 $pass = '*****';
 $cnx = mysql_connect ($hote, $user, $pass) or die(mysql_error ());
 $ret = mysql_select_db ($base) or die (mysql_error ());
 $image_id = mysql_real_escape_string($_GET['ID']);
 $sql = "SELECT image FROM image_upload WHERE ID ='$image_id'";
 $result = mysql_query($sql);
 $image = mysql_result($result, 0);

 header('Content-Type: text/html');
 echo '<img src="' . $image . '"/>';
 exit;


 ?>

any help would be appreciated, thanks a heap

  • 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-05-31T02:41:59+00:00Added an answer on May 31, 2026 at 2:41 am

    From what it looks your trying too hard to separate the PHP from HTML.

    // File: index.php
    <?php
        $hote = 'localhost';
        $base = '*****';
        $user = '*****';
        $pass = '*****';
        $cnx = mysql_connect ($hote, $user, $pass) or die(mysql_error ());
        $ret = mysql_select_db ($base) or die (mysql_error ());
        $image_id = mysql_real_escape_string($_GET['ID']);
        $sql = "SELECT image FROM image_upload WHERE ID ='$image_id'";
        $result = mysql_query($sql);
        //$image = mysql_result($result, 0);
    
        $image = array();
    
        while ($row = mysql_fetch_assoc($result)) {
            $image[] = $row["image"];
        }
    ?>
    <html>
        <head>
        </head>
        <body>
            <div class="slide">
                <div class="image-holder">
                    <img src="<?php echo $image[0];?>" alt="" /> 
                </div>
                <div class="info">
                    <p>Morbi a tellus lorem, id scelerisque ligula. Maecenas vitae turpis et.</p>
                </div>
            </div>
            <div class="slide">
                <div class="image-holder">
                    <img src="<?php echo $image[1];?>" alt="" />
                </div>
            <div class="info">
                <p>Sed semper, lorem ac lobortis bibendum, magna neque varius augue, vel accumsan.</p>
            </div>
        </div>
    <div class="slide">
        <div class="image-holder">
            <img src="<?php echo $image[2];?>" alt="" />
        </div>
    </body>
    </html>
    
    
    // This is the magic code to get all the rows out of the database :)
    // $row[ field_name ];
    while ($row = mysql_fetch_assoc($result)) {
        $image[]  $row["image"];
    }
    

    Edit:
    I’m not sure if this is what your trying to accomplish, but thought I’d share anyway.

    $imageID1 = $_GET['id1'];
    $imageID2 = $_GET['id2'];
    $imageID3 = $_GET['id3'];
    
    $sql = "SELECT image FROM image_upload ";
    $sql = "WHERE ID = $imageID1 OR ID = $imageID2 OR ID = $imageID3";
    
    //The rest of your code can remain the same.
    

    Or if one id relates to 3 images.

        $sql = "SELECT * FROM image_upload WHERE ID ='$image_id'";
        $result = mysql_query($sql);
    
        $image = array();
    
        $row = mysql_fetch_assoc($result);
    
        $image1 =  $row["image1"];
        $image2 =  $row["image2"];
        $image3 =  $row["image3"];
    

    I’ve you give me more info on what your trying to do, I’d be happy to give you a better example.

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

Sidebar

Related Questions

Sorry I am sure this is easy but I have spent ages trying to
I'm trying something like this, but this example does not work. jsObj = {};
So this is probably an easy thing that I'm trying to do but I'm
I'm sure there's a really easy way of doing this. I'm trying to take
I'm not sure if I am completely mad or missing something but I am
This probably has an embarrassingly easy answer, but I'm not sure what it is.
I'm trying to do something which I figure would be rather easy, though I'm
I've spent a couple of hours trying to achieve something I thought was easy.
I'm having an issue when trying to do something which should be as easy
I'm sure this will be an easy answer for somebody. I have the following

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.