Ell20 Posted January 14, 2008 Share Posted January 14, 2008 Hi, I have a website which uses one CSS for all sites my users create. However would it be possible to add a feature in the Admin panel for the user to select the basic colour e.g Red, Blue, Green Once submitted the colour of the page can be changed using this? I have a database so I could store say Red into the club table. Then use a query to check what colour is stored then say if($css == Red) { use this css } kind of thing? I hope this kind of makes sense. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/ Share on other sites More sharing options...
john010117 Posted January 14, 2008 Share Posted January 14, 2008 I believed you answered your own question. Let a user submit the color of the page into a database (a simple script should work that part out). Then, whenever that page loads, do a query on the database, and do a simple if/else statement to select the right stylesheet. Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438451 Share on other sites More sharing options...
Ell20 Posted January 14, 2008 Author Share Posted January 14, 2008 I havent tried it yet so I was unsure whether this would be possible and being fairly new to PHP/MySQL I didnt want to get involved with something if it wasnt physically possible to do it in this manner. I shall give it a go! Thanks for the info. Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438453 Share on other sites More sharing options...
john010117 Posted January 14, 2008 Share Posted January 14, 2008 No problem. If you get stuck on any part of your code, post the relevant part of the code, and we'll be glad to help. Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438454 Share on other sites More sharing options...
Ell20 Posted January 14, 2008 Author Share Posted January 14, 2008 Just another quick question. If I want my user to be able to select their own font say Arial, is it possible for that font to be added in? Could it be done in a simular way? Store in the DB then get the information out and put it into the CSS? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438455 Share on other sites More sharing options...
john010117 Posted January 14, 2008 Share Posted January 14, 2008 Of course. Make sure you have different stylesheets for PHP to pick. After all, you can't put variables into stylesheets. Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438457 Share on other sites More sharing options...
Ell20 Posted January 14, 2008 Author Share Posted January 14, 2008 Hmm that makes it harder then, because ill end up having hundreds of stylesheets! Think ill just stick to the colour customisation! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438458 Share on other sites More sharing options...
john010117 Posted January 14, 2008 Share Posted January 14, 2008 Or you could just embed stylesheets into PHP documents Ex: <html> <head> <title>Style</title> <style type="text/css"> body { background-color: <?php echo $bgcolor; ?> } </style> </head> <body> Hi </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438459 Share on other sites More sharing options...
Ell20 Posted January 14, 2008 Author Share Posted January 14, 2008 Oh right so you can add PHP/Variable into stylesheets? Thats excellent! Thanks I can add a lot of customisation using that method! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438461 Share on other sites More sharing options...
john010117 Posted January 14, 2008 Share Posted January 14, 2008 Oh right so you can add PHP/Variable into stylesheets? Thats excellent! Thanks I can add a lot of customisation using that method! Thanks Only stylesheets that are embedded in .php files. NOT external stylesheets. Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438462 Share on other sites More sharing options...
Ell20 Posted January 14, 2008 Author Share Posted January 14, 2008 Argh I see, how annoying is that! Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438463 Share on other sites More sharing options...
DyslexicDog Posted January 14, 2008 Share Posted January 14, 2008 Of course. Make sure you have different stylesheets for PHP to pick. After all, you can't put variables into stylesheets. Actually you can put variables in stylesheets using php. Just need to set the header as text when you deliver the css / php file to the l client. As long as the stylesheet is on your server you can put as much php as you want in it. Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438464 Share on other sites More sharing options...
Ell20 Posted January 14, 2008 Author Share Posted January 14, 2008 Of course. Make sure you have different stylesheets for PHP to pick. After all, you can't put variables into stylesheets. Actually you can put variables in stylesheets using php. Just need to set the header as text when you deliver the css / php file to the l client. As long as the stylesheet is on your server you can put as much php as you want in it. How do you mean? Sorry I dont follow? Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438466 Share on other sites More sharing options...
john010117 Posted January 14, 2008 Share Posted January 14, 2008 <?php header("Content-type: text/css"); ?> /* Rest of your CSS stuff goes here*/ body { background-color: <?php echo $bgcolor; ?> } Save it as something.php and you can call it from another file. That way, you can put variables into external stylesheets. <html> <head> <link href="something.php" rel="stylesheet" type="text/css" /> </head> </html> Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438468 Share on other sites More sharing options...
Ell20 Posted January 14, 2008 Author Share Posted January 14, 2008 Excellent, just was I was looking for. Thanks so much for the help. Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-438471 Share on other sites More sharing options...
Ell20 Posted January 15, 2008 Author Share Posted January 15, 2008 I have just tried this. I have got it working if I just set the variables within the page e.g: <?php header("Content-type: text/css"); $pageBG = '#fff'; ?> body { background:<?=$pageBG?>; } However ideally I would like to be able to use a mysql query to query the database and get the colours entered by the user. Is this possible? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/85881-php-help/#findComment-440214 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.