bschultz Posted July 9, 2010 Share Posted July 9, 2010 How can I get a mysql result to set a background image in a css file? I know how to get the result...just don't know where to put everything. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/207209-php-and-mysql-results-in-css/ Share on other sites More sharing options...
robert_gsfame Posted July 9, 2010 Share Posted July 9, 2010 u mean get the background path which has been stored in database? if it's that what u mean then u can get the background path from your database make sure that background image has been uploaded into your local folder n <body <?php echo "background='mybackground.jpg'";?>> Quote Link to comment https://forums.phpfreaks.com/topic/207209-php-and-mysql-results-in-css/#findComment-1083373 Share on other sites More sharing options...
bschultz Posted July 9, 2010 Author Share Posted July 9, 2010 In my CSS I have this...which sets the background image for a given "div". #center_big_box.home{ background:url(/images/services.gif) no-repeat bottom left #3a3535; I'd like the background:url(/images/services.gif) no-repeat bottom left #3a3535; to change like this...background:url('<?php $row[image_location]; ?>' ) no-repeat bottom left #3a3535; But it's not working. Like I said, I have that in my css file...which is included like any other css file. I've even tried setting the background as a <div style=background:url('<?php $row[image_location]; ?>' )> but that didn't work either. No images show up at all. Quote Link to comment https://forums.phpfreaks.com/topic/207209-php-and-mysql-results-in-css/#findComment-1083374 Share on other sites More sharing options...
xcandiottix Posted July 9, 2010 Share Posted July 9, 2010 The problem is you're calling PHP in a CSS page. Simply change your .css file to .php and it should work fine. Quote Link to comment https://forums.phpfreaks.com/topic/207209-php-and-mysql-results-in-css/#findComment-1083378 Share on other sites More sharing options...
optikalefx Posted July 9, 2010 Share Posted July 9, 2010 use ajax to get the info with PHP then change the CSS with JavaScript Quote Link to comment https://forums.phpfreaks.com/topic/207209-php-and-mysql-results-in-css/#findComment-1083379 Share on other sites More sharing options...
robert_gsfame Posted July 9, 2010 Share Posted July 9, 2010 In my CSS I have this...which sets the background image for a given "div". #center_big_box.home{ background:url(/images/services.gif) no-repeat bottom left #3a3535; I'd like the background:url(/images/services.gif) no-repeat bottom left #3a3535; to change like this...background:url('<?php $row[image_location]; ?>' ) no-repeat bottom left #3a3535; But it's not working. Like I said, I have that in my css file...which is included like any other css file. I've even tried setting the background as a <div style=background:url('<?php $row[image_location]; ?>' )> but that didn't work either. No images show up at all. have u tried to change this background:url('<?php $row[image_location]; ?>' ) into this background:url('<?php $row['image_location']; ?>' ) see the bold single quotes Quote Link to comment https://forums.phpfreaks.com/topic/207209-php-and-mysql-results-in-css/#findComment-1083380 Share on other sites More sharing options...
bschultz Posted July 9, 2010 Author Share Posted July 9, 2010 The problem is you're calling PHP in a CSS page. Simply change your .css file to .php and it should work fine. Did that already...didn't change anything. Quote Link to comment https://forums.phpfreaks.com/topic/207209-php-and-mysql-results-in-css/#findComment-1083385 Share on other sites More sharing options...
andrewgauger Posted July 9, 2010 Share Posted July 9, 2010 try <?php echo $row['image_location'];?> Quote Link to comment https://forums.phpfreaks.com/topic/207209-php-and-mysql-results-in-css/#findComment-1083387 Share on other sites More sharing options...
bschultz Posted July 9, 2010 Author Share Posted July 9, 2010 In my CSS I have this...which sets the background image for a given "div". #center_big_box.home{ background:url(/images/services.gif) no-repeat bottom left #3a3535; I'd like the background:url(/images/services.gif) no-repeat bottom left #3a3535; to change like this...background:url('<?php $row[image_location]; ?>' ) no-repeat bottom left #3a3535; But it's not working. Like I said, I have that in my css file...which is included like any other css file. I've even tried setting the background as a <div style=background:url('<?php $row[image_location]; ?>' )> but that didn't work either. No images show up at all. have u tried to change this background:url('<?php $row[image_location]; ?>' ) into this background:url('<?php $row['image_location']; ?>' ) see the bold single quotes Didn't change anything either Quote Link to comment https://forums.phpfreaks.com/topic/207209-php-and-mysql-results-in-css/#findComment-1083388 Share on other sites More sharing options...
robert_gsfame Posted July 9, 2010 Share Posted July 9, 2010 sorry i forgot to put echo <?php echo $row['image_location'];?> Quote Link to comment https://forums.phpfreaks.com/topic/207209-php-and-mysql-results-in-css/#findComment-1083391 Share on other sites More sharing options...
bschultz Posted July 9, 2010 Author Share Posted July 9, 2010 I'm going to try to simplify this...and NOT change anything with the css file...and instead try to use a <div style> in the main php page. If I use the php in the style sheet, wouldn't I be including a file (the css) BEFORE I've set the variable with the mysql result? Quote Link to comment https://forums.phpfreaks.com/topic/207209-php-and-mysql-results-in-css/#findComment-1083393 Share on other sites More sharing options...
optikalefx Posted July 9, 2010 Share Posted July 9, 2010 leave the CSS alone. CSS files are not meant to by dynamic. Style is separate from function. If you want the style to change on load, then change the style with JS onload. you can use PHP inside of JS as normal, and have the JS change the style when needed. Quote Link to comment https://forums.phpfreaks.com/topic/207209-php-and-mysql-results-in-css/#findComment-1083431 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.