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 7 of 7
  1. #1
    New Coder
    Join Date
    Feb 2010
    Location
    Risalpur/ Pakistan
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to access css code form database into php file?

    hope all will be fine...

    Dear.... i have to ask that.... how to store the css code into data base....

    eg... i have this code


    <style>
    .td_bg_rep{
    background-image:url(images/left-buttons_02.gif);
    background-repeat:repeat-y;
    }
    </style>


    if i assign this code to variable like this $css="the above css code here ";
    and save this into mysql database by using INSERT INTO css_tble query...

    this will store in the database.... but confusion rise here that how to access that code into php file and then implement into my html tag...

    i know that how to include .css file.... but the problem is with database.... how to include it from database...


    Thanks in Advance:

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Why does it need to be in a database?

    Would you rather save it as a file and "include" it?

    <?php include("css.php");?>

  • #3
    New Coder
    Join Date
    Feb 2010
    Location
    Risalpur/ Pakistan
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    Why does it need to be in a database?

    Would you rather save it as a file and "include" it?

    <?php include("css.php");?>
    well Dear....
    i need this in database.. becoz it will be easier to me that edit css code any time... and 2ndly i also want that provide a facility to my user that each user has its own css layout....

    i understand ur this method include(....) but tell me two things...
    will this technique work in my html tags...
    eg.. i have that following css code in my file like this.....

    PHP Code:
    <table width="200" height="400" border="0">
    <
    tr>
         <
    td class="td_bg_rep"hello world </td>
    </
    tr>
    </
    table
    2) tell me that where to include that file..... means in which section...

    u mention in ur method that technique include (css.php);

    but i dont wanna to include any css file... i want directly insert the css code from database...
    by using query...

    eg.... $query=mysql_query("SELECT code FROM css_style WHERE id='2'");

    echo $query;

    i hope u got me now that what thing i want ?
    Last edited by hamayun_4u2004; 11-12-2010 at 04:33 PM.

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Below is sort of an example of how you would put the PHP part at
    the top of your HTML page, and then use the variable inside your HTML ...

    PHP Code:
    <?php
    // connect to your database

    // query the database
    $query=mysql_query("SELECT code FROM css_style WHERE id='2'");
    $row mysql_fetch_assoc($query);

    // at this point, you've queried the database for one column and one id,
    // so you'll end-up with one unique row.  You can now use that in your HTML below.
    ?>

    <html>
    <head>
    </head>
    <?=$row['code']?>
    <body>

    Blah blah ... all of your other HTML stuff

    </body>
    </html>


    When the user sees the web page, it will look like this:

    <html>
    <head>
    </head>
    <style>
    .td_bg_rep{
    background-image:url(images/left-buttons_02.gif);
    background-repeat:repeat-y;
    }
    </style>
    <body>

    Blah blah ... all of your other HTML stuff

    </body>
    </html>





    .

  • #5
    New Coder
    Join Date
    Feb 2010
    Location
    Risalpur/ Pakistan
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    dear... can u tell me that which method is faster and reliable...

    1) including the css style sheet into HTML page...

    OR

    2) Querying the style field from database,,,>>>????

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    While I can't with absolute assurance, I can say with good confidence including the file is much faster.

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    There's two ways to look at this ...

    If you use "includes", you are basically including a file from perhaps 100 files.
    That means, you have those files stored in a directory, and you somehow have
    to manage them.

    By using MySQL (or a database), you still have to manage the entries, but the
    storage of them becomes "data", not "files".

    It's my opinion that using MySQL is easier to manage, searchable, sortable, and easy
    to add other data, more columns, more tables ... whatever you need.

    When it comes to images and photos, I personally like to store them in directories,
    not within MySQL. I leave MySQL for "text data" only ... but that is only a personal
    preference.

    You'll have to decide for yourself which method seems most comfortable and easiest for you.
    With the processor technology today, I don't think you would be able to tell
    which is faster ... it would be a moot point.


    .


  •  

    Posting Permissions

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