部分代码是
while ($row = mysqli_fetch_assoc($result))
{
echo "$row[firstname] $row[lastname]";
echo "<hr>";
echo "<strong>Date Referred:</strong>     $row[cf_831]";
echo "<br/>";
echo "<strong>Date Today:</strong>       $today";
echo "<br/>";
}
例如,我该如何设计此部分的样式?
"$row[firstname] $row[lastname]"
您可以尝试
echo '<p class="mystyle">' . $row['firstname'] . " " . $row['lastname'] . '</p>';
然后添加CSS
.mystyle {
}
Sidsec9的答案补充:如果你害怕样式表,你也可以考虑:
echo '<p style="color: red; font-size: 10pt;">' . $row['firstname'] . " " . $row['lastname'] . '</p>';
您也可以使用样式来摆脱 
,例如使用margin-right
或padding-right
属性。
echo '<p id="name"> '. $row[firstname] $row[lastname] .'</p>';
您只用于name的Css单独使用id,否则使用class并对所有值使用单个Css。#名称{颜色:红色;}
您可以将其封装在一个类中,并使用样式表进行修复。我还更改了echo,允许您关闭PHP标记,做一些HTML,然后再次打开PHP<?=$variable?>
为短回波,与<?php echo $variable; ?>
相同。
while ($row = mysqli_fetch_assoc($result)){
?>
<span class="Example"><?=$row[firstname].' '.$row[lastname]?></span>
<hr>
<strong>Date Referred:</strong>     <?=$row[cf_831]?>
<br/>
<strong>Date Today:</strong>       <?=$today?>
<br/>
<?php
}
一个更好的方法是制作一个html文件,比如example.com
,并放置<!-- FIRSTNAME -->
、<!-- LASTNAME -->
和<!-- TODAY -->
,而不是变量。然后,使用php:
$totalResult = "";
$template_one = file_get_contents("example.html");
while ($row = mysqli_fetch_assoc($result)){
$item = $template_one;
$item = str_replace("<!-- FIRSTNAME -->", $row['firstname'], $item);
$item = str_replace("<!-- LASTNAME -->", $row['lastname'], $item);
$totalResult.= $item; // add to totel result
)
// $today doesnt change in the loop, do it once after the loop is done:
$totalResult = str_replace("<!-- TODAY -->", $today, $totalResult);
echo $totalResult; // Now you have the result in a pretty variable