Jump to content


Photo

PHP & Styles & CSS


  • Please log in to reply
4 replies to this topic

#1 Humpty

Humpty
  • Members
  • PipPipPip
  • Advanced Member
  • 132 posts

Posted 04 April 2006 - 03:11 AM

G'day Guys,

I have a page where a user selects the colours for different Fonts and Tables backgrounds. What I need to do is write this data to either a database or the CSS file.

What would be the best method of doing this in your own opinion(s).

*(I know how to do the database stuff, but unsure how to utilise the info when retireved. (e.g. in my page or can a CSS use PHP)

*(I'm not real flash with working with files but sure I could sort it out, should I rewrite the CSS or just 'edit' the required bits....I don't know how to 'edit' a file using php)

Appreciate any help, understand if none given

- Humpty
  #> Where does the light go when it goes out?

#2 warewolfe

warewolfe
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts
  • LocationOtago, NZ

Posted 04 April 2006 - 09:25 PM

Hej Humpty,
Interesting problem you got there,

A simple way would be if you had a form that took in the desired input on what the fonts and tables looks like and then wrote to a preexisting stylesheet and a page that linked to that css.

First write a stylesheet stub and set the permissions so you can write to it

prewrite all of the information that is static, then have the script append all the dynamic information.

$file ="DynamicStyleSheet.css"
$fh = fopen($file,'a') or die(echo 'File ($file) does not exist';)
fputs($fh, $divContent);
fclose($fh);

(Quick and dirty, need much more comments/error handling here)

where $divContent is a string containing the css code needed to generate the look for a certain div id or class.

This should works but because it it doesn't overwrite the style sheet will get quite long after a while. I'll look into a better way later today.

WW.

#3 Humpty

Humpty
  • Members
  • PipPipPip
  • Advanced Member
  • 132 posts

Posted 05 April 2006 - 11:32 AM

OK....

I've laid out my CSS how I want it, (things that might be added or changed will be appended at the bottom...and fully commented so i can refer to it later)

I am about to use a PHP page and code to:
1) Open the file
2) Write the ENTIRE thing again (over the top of the existing data, completely losing it)
3) Save the file.

Sound like a good plan? or any better ideas at this point in time?

- Humpty
  #> Where does the light go when it goes out?

#4 Humpty

Humpty
  • Members
  • PipPipPip
  • Advanced Member
  • 132 posts

Posted 05 April 2006 - 12:17 PM

Well I just wasted 30 minutes of my life sorting that out.

Why?
When someone opens the page to change colours and doesn't select some colours my CSS will be missing colours.

I think I need a way to either:
1) Load the colours as required from the CSS file
(so that they are listed as default colours in the text boxes that correspond wth the colour pickers)

2) Only edit parts of the CSS file where appropriate
(but I don't know how to edit only PARTS of a file)

Help:
How do I edit only parts of a file, (e.g. a specific line number in a file of lets say 10 lines?)

I know this was in the manual but it didn't make sense to me.

- Humpty
  #> Where does the light go when it goes out?

#5 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 05 April 2006 - 12:20 PM

i would encourage you NOT to actually write the contents that the user pics to a CSS page. as soon as you get a user that's prone to changing things up over and over again or playing with different color combinations, you open yourself up to a mess of overhead trying to overwrite the file every time. here's what i'd suggest:

1) create a CSS file with all the static classes and ids (static being the ones that ARE NOT changeable)

2) create a header file that can be included on every page of your site that declares the dynamic classes and ids within it. rather than hard-coding hex or rgb values into the page, you could use PHP to pull the selected information from a DB and echo it within that style declaration.

3) populate your DB with default values and create an interface where the user can change those values at will.

hope this makes sense to you.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users