简体   繁体   中英

String length of SQL row

I only want to print Reactie eigenaar: " . $bericht['reactie'] when there is content in the database, if it's empty, don't print anything.

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']
}

Quick and dirty:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM