1

我正在尝试使用内联样式在 echo 中应用背景颜色,但它没有应用背景颜色,而是仅更改文本颜色。我想更改代码特定部分的背景颜色

echo "<p style='color:orange';background-color:red;>"."record number: ".$rec_num. "</p>"."<br>"

程序代码是

    class db_access
    {
    private $_uname;
    private $_pass;
    private $_db;
    private $_server;

    //_construct connects databaseand fetchest he result
        public function __construct($server,$user_name,$password,$d_b)
        {
        $this->_server=$server;
        $this->_pass=$password;
        $this->_uname=$user_name;
        $this->_db=$d_b;
        $con=mysql_connect($this->_server,$this->_uname,$this->_pass);

        $db_found=mysql_select_db($this->_db,$con);
        if($db_found)
            {

            $sql="SELECT * FROM login";
            $result = mysql_query($sql);
                if ($result)
                {
                    while ( $db_field = mysql_fetch_assoc($result) ) 
                    {
                    static $rec_num=1;
//inline css
                    echo "<p style='color:orange';background-color:red;>"."record number: ".$rec_num. "</p>"."<br>";
                    print $db_field['ID'] . "<BR>";
                    print $db_field['u_name'] . "<BR>";
                    print $db_field['pass'] . "<BR>";
                    print $db_field['email'] . "<BR><br><br>";
                    $rec_num++;
                    }
                    //returns the connection name that is used as a resource id in __destruct function
                    return $this->_con=$con;        
            }
                else {die(mysql_error());}

            }

        else 
        {return die(mysql_error());}
        } 


        // destruct function closes database    
        public function __destruct()
        {

        $close=mysql_close($this->_con);
        if($close)
        {print "connection closed";}
        else {die(mysql_error());}
        }   

    }
    $db=new db_access("127.0.0.1","root","","fabeeno");

    //var_dump($db);
4

3 回答 3

2

试试喜欢

echo "<p style='color:orange;background-color:red;'>record number: ".$rec_num. "</p><br>";

您必须在样式'后结束单引号。background-color

于 2013-08-17T09:08:17.247 回答
0

或者你可以只调整带有样式的打印线

print "<p style='color: red;border: 1px solid black;height:20px;box-shadow: 1px 1px 7px;'>"."message!: ".$db_field['TEXTAREA1'] . "<br>";

在此之后,我在文本周围得到了一个花哨的盒子=)我在很多方面都喜欢盒子

所以没有回声放置只有print {}功能

多谢,祝你好运

ps ['textarea1']<-- 分配给数据库,因此它只读取该表

于 2014-05-15T13:38:03.930 回答
0

尝试

echo "<div style='background-color:red;'><p style='color:orange'>"."record number:     ".$rec_num. "</p></div>"."<br>";
于 2013-08-17T09:10:32.707 回答