Setting a Background Image problem

Thread Solved

Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Setting a Background Image problem

 
0
  #1
Dec 5th, 2008
Hi All,
I am trying to set background image. I retreived it from the database into $xyzimage variable and then trying it to display in the <body > tag.
When i am trying to display it a tabel cell like <td> it works, but not in <body> tag.
Is there a specific way to do this other than :
  1. $xyzimage;
  2. //retreived it from database
  3. echo '<body BACKGROUND='.$xyzimage.'>';
The same $image works while put in a table cell.

Thankyou all in advance.
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,419
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 229
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Setting a Background Image problem

 
0
  #2
Dec 5th, 2008
Well it could be because the "BACKGROUND" attribute hasn't been used in about 10 years.
  1. <style type="text/css">
  2. background-image:url('<?php echo $xyzimage ?>');
  3. </style>
Last edited by ShawnCplus; Dec 5th, 2008 at 4:21 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Re: Setting a Background Image problem

 
0
  #3
Dec 5th, 2008
Originally Posted by ShawnCplus View Post
Well it could be because the "BACKGROUND" attribute hasn't been used in about 10 years.
  1. <style type="text/css">
  2. background-image:url('<?php echo $xyzimage ?>');
  3. </style>
Thanks fr the quick reply,
Getting error when i use it..

  1. <style type="text/css">
  2. background-image:url('<?php echo $profpic ;?>');
  3. </style>

Parse error: syntax error, unexpected '<'
Last edited by peter_budo; Dec 6th, 2008 at 5:15 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,419
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 229
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Setting a Background Image problem

 
0
  #4
Dec 5th, 2008
heh, the style tags can't show up in PHP code.
For future reference echoing out HTML in PHP can create some serious spaghetti code so you should avoid it if possible.
So instead of echoing you would close your PHP tag, then put in those style tags, then re-open your PHP tags

  1. // some code
  2. ?>
  3. <style type="text/css">
  4. ...
  5. </style>
  6. <?php
  7. // rest of your code
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Re: Setting a Background Image problem

 
0
  #5
Dec 5th, 2008
But how is it possible when my image which is retrieved from database is in a php variable
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,419
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 229
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Setting a Background Image problem

 
0
  #6
Dec 5th, 2008
If you're inside a PHP script you can open and close your PHP tags as much as you want. Anything not inside the tags will be rendered to the browser as text just as if it were in an HTML file.
The code <?php echo $xyzimage ?> in the CSS is what puts the background image in the CSS
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Re: Setting a Background Image problem

 
0
  #7
Dec 5th, 2008
Nope not working this code too..

I tried passing it to switch and echo <body> tag from switch.. but seems no luck here too..
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: Setting a Background Image problem

 
0
  #8
Dec 5th, 2008
Just do this if you want to assign it to the body:
  1. <style type="text/css">
  2. body{
  3. background-image:url('<?php echo $profpic ;?>');
  4. }
  5. </style>
Note: This should go in the head of the document.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Re: Setting a Background Image problem

 
0
  #9
Dec 5th, 2008
Can someone tell me Whats wrong with the below part of the code (

I keep getting parse error
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'
  1.  
  2. //part of the code
  3. echo '
  4. </head>
  5.  
  6. ';
  7. //$home variable is retrieved from a db
  8.  
  9. switch ($homelay){
  10. case 1:
  11. echo "<body BACKGROUND="bckgnd\bg1.jpg">";
  12. break;
  13. case 2:
  14. echo "<body BACKGROUND="bckgnd\bg2.jpg">";
  15. break;
  16. case 3:
  17. echo "<body BACKGROUND="bckgnd\bg3.jpg">";
  18. break;
  19.  
  20.  
  21. default: echo "<body BACKGROUND="bckgnd\bg2.jpg">";
  22. break;
  23. }
  24.  
  25. echo ' <table>';
  26. // rest of the code

the above code is the part which keep giving me Parse error as mentioned above.
Any help is appreciated.
Thankyou
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Re: Setting a Background Image problem

 
0
  #10
Dec 5th, 2008
Originally Posted by buddylee17 View Post
Just do this if you want to assign it to the body:
  1. <style type="text/css">
  2. body{
  3. background-image:url('<?php echo $profpic ;?>');
  4. }
  5. </style>
Note: This should go in the head of the document.
Hi thank you fr the reply

i keep getting same parse error ..
when i tried this one
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC