我正在尝试使用内联样式在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);
答案 0 :(得分:2)
尝试
echo "<p style='color:orange;background-color:red;'>record number: ".$rec_num. "</p><br>";
您必须在'
样式后结束background-color
单引号。
答案 1 :(得分:0)
尝试
echo "<div style='background-color:red;'><p style='color:orange'>"."record number: ".$rec_num. "</p></div>"."<br>";
答案 2 :(得分: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']
&lt; - 被分配给数据库,因此它只读取该表