|
 |
|
 |
06-23-2005, 11:35 AM
|
#1 (permalink)
|
|
Regular Contributor
Join Date: Apr 2004
Location: Orange County, CA
Posts: 123
|
Dynamic CSS files with PHP
Does anyone out there have any experience with Dynamic CSS files with PHP? I'm trying to set a randomized background image for a div layer out of five background images I have -- the images themselves are stored in a database (which they need to be for reasons I'm not going to get into here) and need a processor to be interpreted. I think this may be the problem, because the processor is working, the other elements of the CSS file are working, and the pages that pull from it are seeing everything else. Unfortunately, none of the background images appear in the layer, as called here:
Code:
<div class="mainbody"><img src="images/title.gif">
testing one two three<br /><br /><br /><br /><br /><br /><br /><br /></div>
But here's the relevant chunk of the CSS, see if you can see anything here.
Code:
<?php
header("Content-Type: text/css");
include("includes/sqlconn.php");?>
#mainbody{
position:absolute;
top:0px;
width:100%;
height:100%;
margin:0px auto;
text-align:left;
background-image:url(http://www.mysite.net/images/image_processor.php?id=<?php $query="SELECT id FROM photos ORDER by rand() LIMIT 1";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result)) {
echo($row['id'].");");
}
?>
Incidentally, in this case the randomization is less valuable to me than being able to store the images in the database. Any ideas would be appreciated.
|
|
|
06-23-2005, 11:58 AM
|
#2 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,475
|
have you tried to hard-code the image url in there to see if it works without the query? this is interesting. you are 100% sure the content-type header info is getting set correctly in image_processor.php?
__________________
Mike
|
|
|
06-23-2005, 12:07 PM
|
#3 (permalink)
|
|
Regular Contributor
Join Date: Apr 2004
Location: Orange County, CA
Posts: 123
|
Yes, I have . . . sorry I didn't mention that.
As to the content-type header info, the fact that I can pull the image up independently by calling the image_processor.php file would seem to indicate that the header info is correct.
|
|
|
06-23-2005, 12:14 PM
|
#4 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,475
|
how about browsers? is the problem the same in different browser? at this point i don't have any good suggestions.. i'm just curious.
__________________
Mike
|
|
|
06-23-2005, 12:17 PM
|
#5 (permalink)
|
|
Regular Contributor
Join Date: Apr 2004
Location: Orange County, CA
Posts: 123
|
LOL . . . yes, the problem is the same in firefox and ie . . . which are all I have available to me at the moment. You're actually helping me a great deal. I have respect for you knowledge of PHP, and you're suggesting I try all the things I've already tried, so I must be on the right track, or at least thinking about it correctly.
=+)
|
|
|
06-23-2005, 01:28 PM
|
#6 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
|
shouldn't it just be 'background: url( "generatedurl.jpg" )' instead of 'background-image: url(generated_image.jpg)'? Note the quotes.
__________________
Stop intellectual property from infringing on me
|
|
|
06-23-2005, 01:39 PM
|
#7 (permalink)
|
|
Regular Contributor
Join Date: Apr 2004
Location: Orange County, CA
Posts: 123
|
background-image is valid CSS, but I tried it with both that and just background, and also with the quotes, and still nothing. CSS doesn't like my image processor, I guess. I do believe, however, that it's making valid images . . . check out the ugly little sample jpeg at: http://www.danielcarney.net/images/i...essor.php?id=3
|
|
|
06-23-2005, 01:52 PM
|
#8 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
|
This worked fine for me in firefox as the background element of an h2 tag.
Code:
background: url("http://www.danielcarney.net/images/image_processor.php?id=3");
EDIT: It just occurred to me, is your web server set up to parse the .css file as php?
__________________
Stop intellectual property from infringing on me
|
|
|
06-23-2005, 02:50 PM
|
#9 (permalink)
|
|
Regular Contributor
Join Date: Apr 2004
Location: Orange County, CA
Posts: 123
|
Wow. Still not working for me, however.
I host with an outside company, so I'm not sure how to check about the parsing -- but it's reading other tags from the css-as-php page, so I assume it is.
|
|
|
06-23-2005, 02:52 PM
|
#10 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
|
Just load up the url of the css file directly in your browser and see if you see your code or the proper css output.
__________________
Stop intellectual property from infringing on me
|
|
|
06-23-2005, 04:16 PM
|
#11 (permalink)
|
|
Senior Contributor
Join Date: Mar 2005
Posts: 661
|
CSS is designed to keep downloading of your webpages small and fast.
If you use dynamic CSS the whole idea of CSS is actualy lost.
|
|
|
06-23-2005, 05:22 PM
|
#12 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
|
What the heck are you talking about DJMaze? There's no difference a far as the browser is concerned with the dynamic or non dynamic version (once it works). All this happens in the server. This doesn't affect the fact that he doesn't need load of tables to accomplish layout and it doesn't affect the browser's ability to cache the images.
__________________
Stop intellectual property from infringing on me
|
|
|
06-23-2005, 06:41 PM
|
#13 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,475
|
Quote:
|
Originally Posted by DJMaze
CSS is designed to keep downloading of your webpages small and fast.
|
what was PHP and MySQL designed for? hehe .. i like dynamic style sheets.
__________________
Mike
|
|
|
06-23-2005, 07:12 PM
|
#14 (permalink)
|
|
Regular Contributor
Join Date: Apr 2004
Location: Orange County, CA
Posts: 123
|
And it's only one effect, after all. Teknomage, I have looked at the php in a web browser and it is appearing correctly. Ok, another board I've posted the problem on gives me this but doesn't explain it. Any ideas?
"You can't use dynamic CSS background as the final code is phased as CSS and not PHP so it does not understand it. "
|
|
|
06-23-2005, 08:56 PM
|
#15 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
|
Quote:
|
You can't use dynamic CSS background as the final code is phased as CSS and not PHP so it does not understand it.
|
I'm guessing that poster was suspecting the same thing that I was, namely that css file wasn't being passed through the php interpreter.
Okay assuming your test site is here http://www.danielcarney.net/ , your mainbody is defined as a class which means in CSS is should be addressed as .mainbody # is for id.
EDIT: I should have seen that in your first post...
__________________
Stop intellectual property from infringing on me
Last edited by teknomage1; 06-23-2005 at 09:16 PM.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 07:04 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|