且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DIV标签在php中创建新行

更新时间:2022-10-23 10:29:07

考虑使用< span> 而不是< div>

< span> 已经是内嵌标签,其中< div> 默认为块,它为内容创建一个新行它。


I am trying to style results from database but when I echo <div> it is creating new line after each result. How can I force the div not to create a new line?

.message {
    border:2px solid;
    background-color:white;
}

php

$user = $_SESSION['username'];
$mydb = new mysqli('localhost', 'root', '', '');
$stmt = $mydb->prepare("SELECT * FROM messages where from_user = ?  ");
$stmt->bind_param('s', $user);
$stmt->execute();

$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    echo"<div class='message'>";

    echo $row['to_user'];

    echo"</div>";
}

Consider using <span> instead of <div>

<span> are already inline tags where <div> are blocks by default, which create a new line for the content in it.