如何在回声中更改背景颜色 [英] how to change background colour in echo

查看:47
本文介绍了如何在回声中更改背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用内联样式在回声中应用背景颜色,但未在应用背景颜色,但是仅更改了文本颜色.我想在代码的特定部分更改背景颜色

i am trying to apply the background color in echo using an inline style but it is not applying background color in however changes only the text color. i want to change background color in a particular part of the code

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);

推荐答案

尝试一下

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

您必须在 background-color 样式后加上'单引号.

You have to end ' single quote after the background-color style.

这篇关于如何在回声中更改背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆