1

インライン スタイルを使用してエコーで背景色を適用しようとしていますが、背景色を適用していませんが、テキストの色のみが変更されます。コードの特定の部分の背景色を変更したい

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

試す

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