SQL行的字符串长度

时间:2016-01-08 20:26:17

标签: php sql

我只想打印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>");

2 个答案:

答案 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>");
}