SQL行的字符串长度


String length of SQL row

当数据库中有内容时,我只想打印Reactive eigenaar:".$bericht['recie'],如果它是空的,就不要打印任何内容。

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>");
if ($bericht['reactie'] != '') {
    // print content that depends on $bericht['reactie']
}

快速且肮脏:

if ( strlen(trim($bericht['recentie'] ))) {
    print("<tr><td class='guestbookcontent'>Bericht: " . $bericht['recentie'] . "</td></tr>");
}