Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 06-23-2005, 11:35 AM   #1 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 123
metazai is on a distinguished road
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.
metazai is offline   Reply With Quote
Old 06-23-2005, 11:58 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 06-23-2005, 12:07 PM   #3 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 123
metazai is on a distinguished road
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.
metazai is offline   Reply With Quote
Old 06-23-2005, 12:14 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 06-23-2005, 12:17 PM   #5 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 123
metazai is on a distinguished road
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.

=+)
metazai is offline   Reply With Quote
Old 06-23-2005, 01:28 PM   #6 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
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
teknomage1 is offline   Reply With Quote
Old 06-23-2005, 01:39 PM   #7 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 123
metazai is on a distinguished road
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
metazai is offline   Reply With Quote
Old 06-23-2005, 01:52 PM   #8 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
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
teknomage1 is offline   Reply With Quote
Old 06-23-2005, 02:50 PM   #9 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 123
metazai is on a distinguished road
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.
metazai is offline   Reply With Quote
Old 06-23-2005, 02:52 PM   #10 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
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
teknomage1 is offline   Reply With Quote
Old 06-23-2005, 04:16 PM   #11 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 661
DJMaze is on a distinguished road
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.
DJMaze is offline   Reply With Quote
Old 06-23-2005, 05:22 PM   #12 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
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
teknomage1 is offline   Reply With Quote
Old 06-23-2005, 06:41 PM   #13 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 06-23-2005, 07:12 PM   #14 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 123
metazai is on a distinguished road
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. "
metazai is offline   Reply With Quote
Old 06-23-2005, 08:56 PM   #15 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
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.
teknomage1 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP 5.0.4 and 4.3.11 Released sde Code Newbie News 0 04-20-2005 10:56 AM
PHP vs .NET Redline Lounge 1 11-24-2004 06:10 AM
Installing and using CMUgraphics library. Valmont Standard C, C++ 12 03-29-2003 08:39 AM


All times are GMT -8. The time now is 07:04 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting