gpt4 book ai didi

php - 使固定宽度
的序列按四行显示

转载 作者:行者123 更新时间:2023-11-28 16:00:46 25 4
gpt4 key购买 nike

我有这个代码:

<div style="margin: 0 auto; display:block; width: 916px; overflow: auto;">
<?php echo "";


echo "<i>Owned: $line->phone </i><br><br>";

$query = "SELECT person_id, person.name, person.sex, person.father_id, person.mother_id,PhotosComp.reference as reference
FROM person

WHERE person.id=$currId";
$result = mysql_query($query);
if (mysql_num_rows($result)>0) {
while ($line = mysql_fetch_object($result)) {



echo "<div valign='top'>";

echo "";


echo "<img src=".$line->reference." style=float:left; height='50px' border='1'>";

echo "";
echo "<a href='details.php?id=$line->person_id'>";
echo "<b>";
echo "$line->name</a>";
echo "</b>, <font size='-2'>(";
echo "$line->sex";
echo ", </font><font size='-2'>";
echo "$line->father_id";
echo "<br>";
echo "$line-mother_id";
echo "<br>";
echo "</div>";
}

}echo "";
?>
</div>

信息在垂直方向上显示正确……但我想在换行之前水平显示 4 个结果。

所以我现在从数据库中得到这个结果:

PICTURE  Bob           Mick            JanePICTURE  Roy           Mack            JunePICTURE  Mia           Roy             JanePICTURE  Lou           Bob             JunePICTURE  Bib           Mock            JinePICTURE  Beb           Muck            JonePICTURE  Ray           Rob             Mia

并希望它显示为:

PICTURE  Bob          PICTURE  Roy        PICTURE  Mia       PICTURE  Lou         Mick                  Mack                Roy                Bob         Jane                  June                Jane               JunePICTURE  Bob          PICTURE  Roy        PICTURE  Mia                Mick                  Mack                Roy                      Jane                  June                Jane   

DB 的结果可以是 0 到 15–20。我不需要任何上限。

最佳答案

试试这个,如果有效请告诉我。

if (mysql_num_rows($result)>0) 
{

$counter = 0;

while ($line = mysql_fetch_object($result))
{


if($counter %4 != 0)
{
#this will break your div
echo "<div valign='top' style='clear:both;'>";
}
else
{
echo "<div valign='top' style='float:left;display:block;'>";
}


//if ($line->reference = (NULL)) { echo "<img src=".$line->reference." style=float:left; height='50px' border='1'>";
//else echo "<img src='../temp_pic.jpg' style=float:left; height='50px' border='1'>";}
echo "";
echo "<a href='page.php?id=$line->person_id'>";
echo "<b>";
echo "$line->name</a>";
echo "</b><br>";


echo "line->father_id";
echo"<br>";
echo "line->mother_id";

$counter++;

}
echo "</div>";
}

关于php - 使固定宽度 <div> 的序列按四行显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21575647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com