Forum Moderators: coopster

Message Too Old, No Replies

populating variable in database field

         

defanjos

11:10 pm on Dec 10, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not quite sure how to explain this, but here's a very simplified explanation what I am trying to do.

I have a file (css.php) that gets content of two fields in a database:


Field 1 = #333333
Field 2 = color: <?php echo $font_color; ?>;


I set the variables:
$font_color = Field 1
$css = Field 2


How can I write to the page $css but have it pull the value of $font_color?


If I do:
echo #css;

I want:
color: #333333;

I get:
color: <?php echo $font_color; ?>;


Can you point me in the right direction
Thanks in advance

defanjos

11:37 pm on Dec 10, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I found a solution.

Instead of "color: <?php echo $font_color; ?>;" , I'm using "color:<< font_color >>;" for Field 2

then I use the replace function to replace << font_color >> with the value of Field 1 (#333333 )

penders

12:06 am on Dec 11, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You shouldn't (need to) be using str_replace() for something like this?

I'm not sure exactly how your data is pulled together, but if $font_color holds the value you want to output, then either use string concatenation:
echo 'color: '.$font_color;


Or variable parsing:
echo "color: $font_color";


Or are you trying to do something else?