Creating a Dynamic PHP/CSS Page (newbie design question)
Creating a Dynamic PHP/CSS Page (newbie design question)
am 05.11.2009 17:06:36 von cool
Hi Folks,
My goal: is to have a template form to control css styles, where the
user fills out choices in a template form page and the results might
get stored in a MysQL prefs table.
But I guess you can't have php mixed with .CSS page ... so is the
best way to do this like: ...?
- set a a normal mystyle.css style sheet with no php but with all
possible choices
- then - on the css prefs form page you might have choices like:
fontsize = small or med or big etc. then you might store the 'actual'
css name (on the real css style sheet) associated with the choice like :
style = "HEADER1" or whatever based on the choice
then let's say I have a page:
mypage.php
that links to a css style sheet:
mystyle.css
- then the php page might use it like:
class = "" for "HEADER1"
Q: Is that the best way to setup dynamic css choices using php?
Any comments would be appreciated - dave
Thanks,
cool@hosting4days.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Creating a Dynamic PHP/CSS Page (newbie design question)
On Thu, 2009-11-05 at 08:06 -0800, cool@hosting4days.com wrote:
> Hi Folks,
>
> My goal: is to have a template form to control css styles, where the
> user fills out choices in a template form page and the results might
> get stored in a MysQL prefs table.
>
> But I guess you can't have php mixed with .CSS page ... so is the
> best way to do this like: ...?
>
> - set a a normal mystyle.css style sheet with no php but with all
> possible choices
>
> - then - on the css prefs form page you might have choices like:
>
> fontsize = small or med or big etc. then you might store the 'actual'
> css name (on the real css style sheet) associated with the choice like :
> style = "HEADER1" or whatever based on the choice
>
>
> then let's say I have a page:
>
> mypage.php
>
> that links to a css style sheet:
>
> mystyle.css
>
> - then the php page might use it like:
>
> class = "" for "HEADER1"
>
> Q: Is that the best way to setup dynamic css choices using php?
>
> Any comments would be appreciated - dave
>
>
> Thanks,
> cool@hosting4days.com
>
>
>
>
>
>
You can point your stylesheet link to a PHP file like this:
type="stylesheet" href="css.php" type="text/css">
and then in your PHP script, make sure you set your output header type
to text/css like so:
header("Content-Type: text/css");
That way, your PHP script can output exactly what CSS you require.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--=-gGSX5ipEf9L0y6K7xM+t--
Re: Creating a Dynamic PHP/CSS Page (newbie design question)
am 05.11.2009 17:31:10 von Shawn McKenzie
cool@hosting4days.com wrote:
> Hi Folks,
>
> My goal: is to have a template form to control css styles, where the
> user fills out choices in a template form page and the results might get
> stored in a MysQL prefs table.
>
> But I guess you can't have php mixed with .CSS page ... so is the best
> way to do this like: ...?
>
> - set a a normal mystyle.css style sheet with no php but with all
> possible choices
>
> - then - on the css prefs form page you might have choices like:
>
> fontsize = small or med or big etc. then you might store the 'actual'
> css name (on the real css style sheet) associated with the choice like :
> style = "HEADER1" or whatever based on the choice
>
>
> then let's say I have a page:
>
> mypage.php
>
> that links to a css style sheet:
>
> mystyle.css
>
> - then the php page might use it like:
>
> class = "" for "HEADER1"
>
> Q: Is that the best way to setup dynamic css choices using php?
>
> Any comments would be appreciated - dave
>
>
> Thanks,
> cool@hosting4days.com
>
Maybe setup your table like this:
selector style value
-------------------------------------
HEADER1 font-size small
HEADER1 color black
etc...
Then have a PHP page (user_styles.php) that queries the DB for the
styles and echoes them:
$result = query("SELECT * from user_styles WHERE userid = $userid");
Then just link the PHP page as a stylesheet in your HTML:
--
Thanks!
-Shawn
http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Creating a Dynamic PHP/CSS Page (newbie design question)
am 05.11.2009 17:41:38 von Shawn McKenzie
Shawn McKenzie wrote:
> cool@hosting4days.com wrote:
>> Hi Folks,
>>
>> My goal: is to have a template form to control css styles, where the
>> user fills out choices in a template form page and the results might get
>> stored in a MysQL prefs table.
>>
>> But I guess you can't have php mixed with .CSS page ... so is the best
>> way to do this like: ...?
>>
>> - set a a normal mystyle.css style sheet with no php but with all
>> possible choices
>>
>> - then - on the css prefs form page you might have choices like:
>>
>> fontsize = small or med or big etc. then you might store the 'actual'
>> css name (on the real css style sheet) associated with the choice like :
>> style = "HEADER1" or whatever based on the choice
>>
>>
>> then let's say I have a page:
>>
>> mypage.php
>>
>> that links to a css style sheet:
>>
>> mystyle.css
>>
>> - then the php page might use it like:
>>
>> class = "" for "HEADER1"
>>
>> Q: Is that the best way to setup dynamic css choices using php?
>>
>> Any comments would be appreciated - dave
>>
>>
>> Thanks,
>> cool@hosting4days.com
>>
>
> Maybe setup your table like this:
>
> selector style value
> -------------------------------------
> HEADER1 font-size small
> HEADER1 color black
> etc...
>
> Then have a PHP page (user_styles.php) that queries the DB for the
> styles and echoes them:
>
> $result = query("SELECT * from user_styles WHERE userid = $userid");
>
> while($row = fetch_assoc($result)) {
> echo $row['selector']." { ".$row['style'].": ".$row['value']." }\n";
> }
>
> Then just link the PHP page as a stylesheet in your HTML:
>
>
>
>
>
Obviously you'd also want the userid and most likely a PK in the table
also :-)
id userid selector style value
-----------------------------------------------------
And also probably what Ash said:
header("Content-Type: text/css");
--
Thanks!
-Shawn
http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Creating a Dynamic PHP/CSS Page (newbie design
am 05.11.2009 17:53:30 von Andrew Ballard
On Thu, Nov 5, 2009 at 11:31 AM, Shawn McKenzie wrot=
e:
> Maybe setup your table like this:
>
> selector     style     =C2=
=A0 value
> -------------------------------------
> HEADER1     font-size    small
> HEADER1     color     =C2=
=A0 black
> etc...
If you do this, you'll probably want to add a sequence number column
to ensure that your directives are output in the correct order in
consideration of CSS inheritance rules.
Andrew
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Creating a Dynamic PHP/CSS Page (newbie design question)
am 05.11.2009 18:14:04 von TedD
At 8:06 AM -0800 11/5/09, cool@hosting4days.com wrote:
>But I guess you can't have php mixed with .CSS page
header("Content-type: text/css");
$color = "green"; // <--- define the variable
echo <<
/* --- start of css --- */
..title-text
{
color: $color; /* <--- use the variable */
font-weight: bold;
font-size: 1.2em;
text-align: left;
}
/* --- end of css --- */
CSS;
?>
-------------------------
2 - I created this test page called testcss.php with these contents:
PROBLEM: the 'test1' style shows up - but the 'title-text' doesn't
seem to work
btw: even added this : media="screen" from demo ....
How do I get it to show up?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Creating a Dynamic PHP/CSS Page (newbie design question)
am 05.11.2009 21:13:36 von Shawn McKenzie
cool@hosting4days.com wrote:
> SORRY FOR THE EXTRA 2 BAD pre SENDS (accident...)
>
>
> Thank for all the help!
>
> Getting there... as a baby step - I'm trying this:
>
> (part of this is from - http://sperling.com/examples/pcss/)
>
> 1 - I created this style sheet page called css.php with these contents:
>
> ================
>
> .test1 {
> font-family: Verdana, Arial, Helvetica, sans-serif;
> color: #0099FF;
> font-size: 18px;
> }
>
>
> header("Content-type: text/css");
> $color = "green"; // <--- define the variable
> echo <<
> /* --- start of css --- */
> .title-text
> {
> color: $color; /* <--- use the variable */
> font-weight: bold;
> font-size: 1.2em;
> text-align: left;
> }
> /* --- end of css --- */
> CSS;
> ?>
>
> -------------------------
>
> 2 - I created this test page called testcss.php with these contents:
>
> PROBLEM: the 'test1' style shows up - but the 'title-text' doesn't seem
> to work
> btw: even added this : media="screen" from demo ....
> How do I get it to show up?
>
> ======
>
>
>
>
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
>
On Thu, 2009-11-05 at 14:13 -0600, Shawn McKenzie wrote:
> cool@hosting4days.com wrote:
> > SORRY FOR THE EXTRA 2 BAD pre SENDS (accident...)
> >
> >
> > Thank for all the help!
> >
> > Getting there... as a baby step - I'm trying this:
> >
> > (part of this is from - http://sperling.com/examples/pcss/)
> >
> > 1 - I created this style sheet page called css.php with these contents:
> >
> > ================
> >
> > .test1 {
> > font-family: Verdana, Arial, Helvetica, sans-serif;
> > color: #0099FF;
> > font-size: 18px;
> > }
> >
> >
> > header("Content-type: text/css");
> > $color = "green"; // <--- define the variable
> > echo <<
> > /* --- start of css --- */
> > .title-text
> > {
> > color: $color; /* <--- use the variable */
> > font-weight: bold;
> > font-size: 1.2em;
> > text-align: left;
> > }
> > /* --- end of css --- */
> > CSS;
> > ?>
> >
> > -------------------------
> >
> > 2 - I created this test page called testcss.php with these contents:
> >
> > PROBLEM: the 'test1' style shows up - but the 'title-text' doesn't seem
> > to work
> > btw: even added this : media="screen" from demo ....
> > How do I get it to show up?
> >
> > ======
> >
> >
> >
> >
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> >
> >
> >
> > Untitled Document
> >
> >
> >
> >
> >
> >
test this
> >
> >
and this
> >
> >
> >
> >
> > ===================
> >
> >
> > Thanks,
> > cool@hosting4days.com
>
> You need to do the header() before anything else.
>
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>
Like I mentioned in my first reply to this, you need to set the content
type of the output in css.php:
header("Content-Type: text/css");
That way, the server sends down the right headers to the agent that is
requesting the CSS. By default, PHP outputs a content type of text/html,
and your browser thinks it got HTML instead of CSS so does nothing.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--=-KLiBO6HbI1UD1zM0rBzL--
Re: Creating a Dynamic PHP/CSS Page (newbie design question)
am 05.11.2009 22:58:23 von TedD
At 8:16 PM +0000 11/5/09, Ashley Sheridan wrote:
>On Thu, 2009-11-05 at 14:13 -0600, Shawn McKenzie wrote:
>
> > > Getting there... as a baby step - I'm trying this:
>> >
> > > (part of this is from - http://sperling.com/examples/pcss/)
>
> >
> > You need to do the header() before anything else.
I'm not ragging on you Ashley, but what he needs to do is follow the
directions as outlined in my example.
I really find it frustrating when I take the time to make things as
simple as possible and then have people who don't want to take the
time to understand what's being presented to them.
He could have his entire problem solved if he would only read and
follow the documentation instead of throwing stuff together as if it
will somehow work.
This reminds me of my first memory when I was two years old. You see,
I had a wagon and I wanted it to run like cars do. I knew that my
wagon didn't have what it took to make it run, so I started throwing
stuff into it in the hopes that somehow everything would come
together and the wagon would automagically run.
Well... it didn't run!
So, I stopped trying to solve things that way when I was two. I'm
just surprised how long it takes others to discover that simple fact.