...

View Full Version : how to access css code form database into php file?



hamayun_4u2004
11-12-2010, 03:47 PM
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:

mlseim
11-12-2010, 04:09 PM
Why does it need to be in a database?

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

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

hamayun_4u2004
11-12-2010, 05:30 PM
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.....



<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 ?

mlseim
11-12-2010, 07:06 PM
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
// 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>




.

hamayun_4u2004
11-13-2010, 07:59 PM
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,,,>>>????

Keleth
11-13-2010, 08:19 PM
While I can't with absolute assurance, I can say with good confidence including the file is much faster.

mlseim
11-13-2010, 09:21 PM
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.


.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum