我只想打印Reactie eigenaar:“。$ bericht ['reactie']当数据库中有内容时,如果它是空的,则不打印任何内容。
print("<h2>Guestbook</h2>");
$stmt = $pdo->prepare("SELECT gebruikersnaam,recentie, reactie FROM gastenboek");
$stmt->execute();
$berichten = $stmt->fetchAll();
foreach ($berichten as $bericht) {
//print username
print("<table class='guestbook'");
print("<tr>");
print("<td class='guestbooktitle'>Gebruikernaam: " . $bericht['gebruikersnaam'] . "</td>");
print("</tr>");
//print content
print("<tr>");
print("<td class='guestbookcontent'>Bericht: " . $bericht['recentie'] . "</td>");
print("</tr>");
print("</tr><tr></tr><tr></tr><tr>");
//The owner can comment on the content else if the owner doesn't comment, I don't want Reactie Eigenaar to display
$stmt = $pdo->prepare("SELECT bericht FROM gastenboek");
if ($stmt != 0) {
print("<tr class='reactie'>");
print("<td class=''>Reactie eigenaar: " . $bericht['reactie'] . "</td>");
print("</tr>");
} else {
print("");
}
print("<br>");
}
print("</table>");
print("<br>");
答案 0 :(得分:2)
if ($bericht['reactie'] != '') {
// print content that depends on $bericht['reactie']
}
答案 1 :(得分:0)
又快又脏:
if ( strlen(trim($bericht['recentie'] ))) {
print("<tr><td class='guestbookcontent'>Bericht: " . $bericht['recentie'] . "</td></tr>");
}