dongshi8038 2018-03-28 22:03
浏览 43
已采纳

PHP - 逐位回显sql结果

the below code is working as expected:

    if($con){
        mysqli_select_db($con, "db3");
        $query1 = "SELECT * FROM data WHERE id = $id";
        $result = mysqli_query($con, $query1);
        while ($row = mysqli_fetch_array($result)){
            echo "<b>" . "Sent by: " . $row['uname'] . ":" . "</b>" . "<br>" . $row['comment'] . "<br>" . "<u>" . "Sent on: " . $row['time'] . "</u>" . "<br><br>";
                }

My issue is the the 'comment' value can be pretty long and prints off screen. Is there any way to echo out the 'comment' value 50 characters at a time for example, or insert a line break within it.

Any help appreciated. Thanks.

  • 写回答

1条回答 默认 最新

  • dongnigeng1295 2018-03-28 22:07
    关注

    You can use wordwrap for that.

    wordwrap($row['comment'], 50, '<br>')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?