Question

Everytime I check the HTML output of this piece of code, the slashes aren't included. Thus, the background image fails. I even put it through a html to php converter. Im lost; please help.

while($row = mysql_fetch_array($data))
{
    //Echo Theme Template on pages  
    echo "<div style='background-image:url('../uploads/avi/{$row['avi']}')></div>";
    echo "<div class='myname'>{$me}</div>"; 
}
Was it helpful?

Solution 2

You did two things wrong here. You never closed the final quote for the style tag, and using single quotes for both style='' and the url('') cancelled each other out.

I'd recommend always using double quotes for HTML tags.

while($row = mysql_fetch_array($data))
//Echo Theme Template on pages
{
    echo "<div style=\"background-image:url('../uploads/avi/{$row['avi']}');\"></div>";
    echo "<div class='myname'>{$me}</div>";
}

Another thing to consider, always say "View Source" instead of "Inspect" with Firebug or some other tool. The reason you didn't see the URL printed out is because new browsers are "Smart" and try to fix DOM errors. Inspecting the source with Firebug or a similar tool will show you what the browser actually interprets. Viewing the source will show what was actually sent to the browser.

OTHER TIPS

the simplest answer would be, you have an unclosed ' on your style attribute..

echo "<div style='background-image:url('../uploads/avi/{$row['avi']}')'></div>";
                                                                                                                                              ^here

but this wouldn't work as is.. so you should adjust the quotes like this:

echo "<div style='background-image:url(\"../uploads/avi/{$row['avi']}\");'></div>";

you can see the broken echo http://codepad.viper-7.com/CGMdUx

and the edited one is here http://codepad.viper-7.com/bEyKFz

i passed it through htmlspecialchars on codepad just so you can see it as string and avoid being rendered as HTML for viewing purposes only..

Because of the inner ' used by the style attribute, you need to use double quotes inside.

echo '<div style="background-image:url(\'../uploads/avi/' . $row['avi'] . "')></div>";

Result

<div style="background-image:url('../uploads/avi/abc.efg')></div>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top