我使用sql查询从数据库打印数据,但是当我得到输出时,我没有得到所需的形式。
部分代码是
$result1 = mysqli_query($con,"SELECT * FROM abc where id='".$a."'");
if (mysqli_num_rows($result1) > 0)
{
while($row1 = mysqli_fetch_array($result1))
{
echo "<div class='dd' style='width:600px; padding-left:15px;'>";
echo "<div class='col-lg-3' style='font-size:medium;'>";
echo $row1['name'];
echo "</div>";
echo "</div>";
}
}
我得到的输出是
q
w
e
r
然而我希望以
的形式离开q w e
r t y
u u u
非常感谢任何帮助
答案 0 :(得分:2)
试试这个 -
借助 UI&amp; LI html标签你可以做... Sweet&amp;简单的代码:) ..
$result1 = mysqli_query($con,"SELECT * FROM abc where id='".$a."'");
if (mysqli_num_rows($result1) > 0)
{
echo "<div class='list'>";
echo "<ul>";
while($row1 = mysqli_fetch_array($result1)) {
echo "<li>".$row1['name']"</li>";
}
echo "</ul>";
echo "</div>";
}
CSS -
div.list{
display:block;
width:300px;
}
div.list ui{
width:100%;
}
div.list ui li{
float:left;
width:33.333%;
list-style-type:none;
}
演示 - Fiddle
答案 1 :(得分:0)
可以通过CSS Float
属性完成,我们清除float
$counter = 0;
while($row1 = mysqli_fetch_array($result1))
{
$counter++;
$divstyle= 'clear:both';
if($counter % 4 == 0){
$divstyle= 'float:left';
}
echo "<div class='dd' style='width:600px; padding-left:15px;$divstyle;'>";
echo "<div class='col-lg-3' style='font-size:medium;'>";
echo $row1['name'];
echo "</div>";
echo "</div>";
}