-2
I would like to display on a page that I am developing a hexadecimal value that is stored in my database. I did some tests, but without success.
I tried to do something like this:
<?php echo "background-color:".$ProdCor->Cor;.""; ?>
The value in the bank field is like this:
#ffff00
I’m trying to show color in a page field.
The CSS that is related to the field is this:
.tovar_color_select {padding-bottom:19px;} .tovar_color_select p { margin-bottom:13px; text-transform:uppercase; font-weight:900; font-size:12px; color:#333; } .tovar_color_select a { position:relative; display:inline-block; margin-right:10px; width:32px; height:22px; }
.tovar_color_select a:before { content:''; position:Absolute; left:-4px; top:-4px; right:-4px; bottom:-4px; border:1px Solid #e9e9e9; Transition: all 0.1s Ease-in-out; -Webkit-Transition: all 0.1s Ease-in-out; } .tovar_color_select a:Hover:before, .tovar_color_select a.active:before { border:2px Solid #333; }
The complete tag is this:
<div class="tovar_color_select">
<p>SELECIONE A COR</p>
<?php foreach($ResCor as $ProdCor ) { ?>
<a href="javascript:void(0);" ><?php echo "background-color:".$ProdCor->Cor; ?></a>
<?php } ?>
What about the rest of the field code? You’re using CSS inline or inserted it into the CSS file?
– Woss
There is a syntax error, a
;
in the middle of concatenation. Also, while not causing an error in the output, concatenate a string with""
in the end is meaningless in that context. It would be enough<?php echo "background-color:".$ProdCor->Cor; ?>
which may be abbreviated to<?='background-color:'.$ProdCor->Cor?>
in newer versions of PHP (in older versions, it depends on configuration)– Bacco
Hello @Bacco, thanks for the tip, but it didn’t work, I edited the question to try to show what I need.
– adventistapr
@adventistapr tested my response?
– Thiago Magalhães
Hello @Thiago Magalhães, also did not work.
– adventistapr
Following my answer code, change the
background-color: <?= $ProdCor->Cor ?>
forbackground-color: #333
. It should print a square with the specified color. Checked if the color is being returned correctly?– Thiago Magalhães