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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:00:50+00:00 2026-05-29T05:00:50+00:00

I am using WAMP. I want to take background image URL from my database

  • 0

I am using WAMP. I want to take background image URL from my database and want to show this in div class ‘box’. I tried it by followed way but couldn’t succeed. the last background image is appearing on each box while I want to show different images. Code I am using is

<?php 
    $feild_set = get_all_feilds();
    while($feild = mysql_fetch_array($feild_set)) { 
        $url = $feild['background_image_url'];
        echo "<style>
            .box { 
                width: 300px ;
                height: 100px;
                background-image: $url;
                background-visibility: visible;
                border: 1px #00FF33;
                margin-bottom: 10px;
                display: inline-table;
                margin-right: 10px;
            }
            </style>";
        echo "<div class=\"box\">";
        echo "<a href=\"content.php?feild=" . $feild['id'] . "\" ><block_holder>{$feild['menu_name']}</block_holder></a>"; 
        echo "</div>";
    }
?>

Thanx in advance

  • 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-29T05:00:51+00:00Added an answer on May 29, 2026 at 5:00 am

    Try this:

    <?php 
    
      echo "
        <style>
          .box { 
            width: 300px ;
            height: 100px;
            background-visibility: visible;
            border: 1px #00FF33;
            margin-bottom: 10px;
            display: inline-table;
            margin-right: 10px;
          }
        </style>";
    
      $field_set = get_all_feilds();
    
      while ($field = mysql_fetch_assoc($field_set)) {
        echo '
        <div class="box" style="background-image:'.htmlspecialchars($field['background_image_url']).';">
          <a href="content.php?feild='.htmlspecialchars($field['id']).'">
            <block_holder>'.htmlspecialchars($field['menu_name']).'</block_holder>
          </a>
        </div>';
      }
    
    ?>
    


    What have I done?

    • Placed the declaration of the .box CSS class outside the loop so it is only output once
    • Changed mysql_fetch_array() to mysql_fetch_assoc() as it is less confusing and more efficient
    • Removed the background-image: property from the .box class
    • Added a background-image: property to an inline style= attribute for each div and wrapped the URL of the image in url() (this has been undone as it seems the URLs are stored in the database with this already done
    • Passed data from the database through htmlspecialchars() before outputting it
    • Corrected the spelling of feild to field where it can be done without breaking the rest of your code
    • Some general indentation and quote tidying and readability fixes

    As it was, your CSS .box class was declared more than once. Because of the cascading nature of CSS, only the values used in the last declaration would have been used – each declaration of a property overrides the last, which is why you were only seeing the last image. You also would not need to declare those details more than once – the whole idea of a class is that you can declare it once and use it multiple times. If you want element-specific properties, use IDs or inline styles (preferably IDs, but I have used inline styles here for simplicity).

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

Sidebar

Related Questions

I am using WAMP. I want to use php from the command prompt. What
Can I get a path like this using PHP ? c:\\wamp\\www\\mysite\\blabla\n from the script
i am downloading tiff images from WAMP server using our Flex AIR client. Using
I want to fetch div element from other website . on which iam having
I'm using WAMP and have a development site in the www directory. I want
I want to remove index.php from url but so far i couldn't succeed it.
So I want to extend for example this RecursiveIterator from the SPL with the
I'm using WAMP. I want to measure the bytes sent and received while viewing
I am using WAMP for my Local Server in Windows 7. I want to
I am using WAMP as my local server and what I want to know

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.