Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Posts
    310
    Thanks
    86
    Thanked 3 Times in 3 Posts

    Changing the value of an external stylesheet using php?

    Hi Guys,

    In the website i'm building I want to change the colour of the background of my site on a regular basis. So I want to change a value in a table in MYSQL and then this colour I enter ie: #0066CC is picked up on my site.

    Now, i've tested this with an internal stylesheet on a php page and it works great, but is this possible with an external stylesheet ie something like:

    php
    Code:
    <?php
     include('php_files/*********.php'); 
     ?>
          <?php
           $SQL = "SELECT body_colour FROM style_test WHERE style_id = 1"; 
           $result = mysql_query($SQL) OR die(mysql_error()); 
           $row = mysql_fetch_array($result); 
           $xx = $row['body_colour'];
          ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <link rel="stylesheet" href="test.css" type="text/css" />
    <title>test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    </body>
    </html>
    stylesheet
    Code:
    body {
       background: <?php echo $xx; ?>;
    }
    However that does not seem to work.

    Also can you query inside an external stylesheet (i'm, guessing not as it's not got a .php extension), ie something like:

    Code:
    <?php
     include('php_files/*********.php'); 
     ?>
          <?php
           $SQL = "SELECT body_colour FROM style_test WHERE style_id = 1"; 
    	   $result = mysql_query($SQL) OR die(mysql_error()); 
           $row = mysql_fetch_array($result); 
    	   $xx = $row['body_colour'];
          ?>
    body {
       background: <?php echo $xx; ?>;
    }
    Thanks

    Chris

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,854
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Yes, add a php extension to your stylesheet; say style.css.php
    Then add the proper header at the top as
    PHP Code:
    <?php
    header
    'Content-type: text/css' ); 
    ?>
    Now you can link this stylesheet, and write any PHP code inside it.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    stfc_boy (02-19-2008)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •