开发者

php array getting placeholder from database

开发者 https://www.devze.com 2023-02-21 13:22 出处:网络
i have this designing my t开发者_开发技巧able: <style type=\"text/css\"> tr { background: <?php echo $colors[$status];?>;

i have this designing my t开发者_开发技巧able:

<style type="text/css">
        tr {
            background: <?php echo $colors[$status];?>;
            color:white;
        }
</style>

and

    $status = $row[4];//value is 0
    $colors = array("lime", "red");

The value in the database is 0.

The $status variable defines what color the table row should be. However the row is never lime. Is my array wrong or something else?


make sure the order is correct.

the order should be something like this:

<?php
    $status = $row[4];//value is 0
    $colors = array("lime", "red");
?>
<style type="text/css">
    tr {
        background: <?php echo $colors[$status];?>;
        color:white;
    }
</style>

your issue could be due to the fact that $colors was never declared before you started using it


If your css is defined in a separate file like "style.css", then your server won't know to parse php code inside. To do that you'll need to use the ".php" extension on your style file and include <?php header('content-type:css);?> at the top so the browser knows to interpret the css declarations.

Read more about using php in your css files here: http://www.barelyfitz.com/projects/csscolor/

0

精彩评论

暂无评论...
验证码 换一张
取 消