我正在尝试创建一个类似电子邮件的系统,其中阅读邮件显示正常,新条目/邮件以粗体显示。我创建了一个css规则来满足文本格式,但我遇到的问题是在我的循环中实现它。
感谢
$stmt = $pdo->query("SELECT * FROM $tbl_name");
$stmt->execute();
$num_rows = $stmt->rowCount();
print "<p>$num_rows Record(s) Found.</p>";
echo "<table width='100%' border='1' bordercolor='#0cc' cellspacing='0' cellpadding='2'>";
echo "<tr>
<th bgcolor='#444444' align='center'><font color='#fff'>Surname</font></th>
<th bgcolor='#444444' align='center'><font color='#fff'>Firstname</font></th>
<th bgcolor='#444444' align='center'><font color='#fff'>Email / Username</th>
<th bgcolor='#444444' align='center'><font color='#fff'>Phone</th>
<th bgcolor='#444444' align='center'><font color='#fff'>Date Registered</th>
<th bgcolor='#444444' align='center'><font color='#fff'>Status</th>
<th bgcolor='#444444' align='center'><font color='#fff'>Create Account</th>
<th bgcolor='#444444' align='center'><font color='#fff'>Delete Account</th>
</tr>";
// keeps getting the next row until there are no more to get
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$clas = $row['entry'];
if($clas == 'NEW'){
$style = "<div style='font-weight:bold'></div>";
}else{
$style = "<div style='font-weight:normal'></div>";
}
// Print out the contents of each row into a table
echo "<tr><td>";
echo ucfirst($row['surname']);
echo "</td><td>";
echo ucfirst($row['firstname']);
echo "</td><td>";
echo $row['email'];
echo "</td><td>";
echo $row['phone'];
echo "</td><td>";
echo $row['today'];
echo "</td><td>";
echo $row['status'];
echo "</td><td>";
echo "<a href='create-account.php?id={$row['id']}'>Create Account</a>";
echo "</td><td>";
echo "<a href='account-delete.php?id={$row['email']}'>Delete Account</a>";
echo "</td></tr>";
}
echo "</table>";
答案 0 :(得分:1)
这可能是你想要达到的目标,但请在下次提出正确的问题。
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$clas = $row['entry'];
if($clas == 'NEW'){
$style = ' style="font-weight:bold"';
}
// Print out the contents of each row into a table
echo "<tr{$style}><td>";
echo ucfirst($row['surname']);
echo "</td><td>";
echo ucfirst($row['firstname']);
echo "</td><td>";
echo $row['email'];
echo "</td><td>";
echo $row['phone'];
echo "</td><td>";
echo $row['today'];
echo "</td><td>";
echo $row['status'];
echo "</td><td>";
echo "<a href='create-account.php?id={$row['id']}'>Create Account</a>";
echo "</td><td>";
echo "<a href='account-delete.php?id={$row['email']}'>Delete Account</a>";
echo "</td></tr>";
}