【发布时间】:2012-11-25 07:57:59
【问题描述】:
我无法设置从数据库中提取的信息的样式。如果有人可以提供帮助,我将不胜感激。我尝试在 while 循环中定义 $style,然后将其分配给 $questions,但网页上没有任何反应。我是一般编码的新手,虽然我对 css 有一些了解,但我不知道你如何在 php 脚本中使用它。
我试图在每个问题后面放置的背景风格*
#frm1
{
background: #D9D9D9;
margin:auto;
top:150px; left:200px; width:880px; height:60px;
position:absolute;
font-family: "Comic Sans MS", cursive, sans-serif;
font-size: 9px;
font-style: italic;
line-height: 24px;
font-weight: bold;
text-decoration: none;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
padding:10px;
border: 1px solid #999;
border: inset 1px solid #333;
-webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.5);
box-shadow: 0px 0px 40px rgba(0, 0, 0, 0.7);
}
PHP 代码从数据库中检索信息*
if (mysql_num_rows($result) >= 0)
{
$toggle = false;
while ($rows = mysql_fetch_array($result, MYSQL_ASSOC) and $i<10 )
{
$i++;
$toggle = !$toggle;
if($toggle)
$style = "id:frm1;";
else
$style = "background: white;";
questions .= "<a style='$style'> </a>";
questions .= "Titlee: " ."<a href='show_question2.php?question_id=" . $rows["question_id"] . "'>". $rows['title'] . "</a> <br> ";
questions .= "Details: " . "<a href='show_question2.php?question_id=" . $rows["question_id"] . "'>". $rows['detail'] . "</a> <br> ";
questions .= "Category: " . "<a href='show_question2.php?question_id=" . $rows["question_id"] . "'>". $rows['categories'] . "</a> <br> <br> <br> ";
}
echo questions;
}
【问题讨论】:
-
你应该改用类;他们将提供更简洁的代码和更大的灵活性。无论如何,这里的问题似乎是带有样式的链接是空的......
-
CSS 类将大大简化这一点。正如您在这里所拥有的那样,您实际上使用的是
<font>标签。 -
我尝试使用 CSS 类,但我不知道如何在 php 中调用它们。
-
style='id:frm1' 不正确;你想要 id='frm1'
-
您应该使用 class 而不是 id。ID 在页面上应该是唯一的。