Bạn có thể quấn nó trong một lớp và sửa nó bằng một biểu định kiểu. Tôi cũng đã thay đổi tiếng vang, bạn được phép đóng thẻ PHP, thực hiện một số HTML và sau đó mở lại PHP.
<?=$variable?>
là tiếng vang ngắn, nó giống như <?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
}
Một phương pháp tốt hơn sẽ được xây dựng và tập tin html, nói example.com
, và đặt <!-- FIRSTNAME -->
, <!-- LASTNAME -->
VÀ <!-- TODAY -->
thay vì các biến. Sau đó, sử dụng 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
" Sợ biểu định kiểu "? Thời gian để đầu tư vào một số liệu pháp! – Martijn
Tôi đề nghị OP chấp nhận câu trả lời của [Sidsec9] (http: // stackoverflow.com/a/31262113/2088851), nó đẹp hơn, sử dụng ít mã hơn và tôi thích giải pháp của họ hơn. – Voitcus