how to change background colour in echo

爷,独闯天下 提交于 2021-02-05 09:25:08

问题


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>"

program code is

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

回答1:


Try like

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

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




回答2:


try

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



回答3:


Or you can ajust only the print lines with styles

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

after this i got an fancy box around the text =) i love boxes in many ways

so no echo where placed only print {} function

Many thanx and good luck

ps ['textarea1'] <-- is assigned to database so it reads only that table



来源:https://stackoverflow.com/questions/18287060/how-to-change-background-colour-in-echo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!