我正在尝试让我的代码显示多个div。但似乎只能正确显示一个div。
<?php
// database connection
//$result = mysqli_query($con,"SELECT * FROM test WHERE field5='Cohen'");
echo " <div id='1'>";
while($row = mysqli_fetch_array($result))
{
echo "<div class='tutorName'>" . $row['field1'] . "</div>";
echo "<div class='tutorPrice'>" . $row['field2'] . "</div>";
echo "<div class='tutorInstitution'>" . $row['field3'] . "</div>";
echo "<div class='tutorLocale'>" . $row['field4'] . "</div>";
echo "<div class='tutorPhone'>" . $row['field5'] . "</div>";
}
echo "</div>";
mysqli_close($con);
?>
我希望以下内容循环使用上面的字段(field1,feild2等):
<div id='' name='' class="column threecol">
<div class="course-preview premium-course">
<div class="course-image">
<a href="listing.php"><img src="img.png" /></a>
<div class="course-price">
<div class="corner-wrap">
<div class="corner"></div>
<div class="corner-background"></div>
</div>
<div class="price-text"><span class="amount">PerHour</span></div>
</div>
</div>
<div class="course-meta">
<header class="course-header">
<h5 class="nomargin">TutorName </h5>
<div class='gender'>Gender: </div>
<div class='price-range'>Price Range: </div>
<div class='institute'> Institute: </div>
</header>
</div>
</div>
</div>
答案 0 :(得分:0)
您的$结果行是否真的在真实代码中被注释掉了?或者您只是为该示例添加了该评论?如果它在您正在测试的代码中被注释掉,那么这可能就是问题所在。
答案 1 :(得分:0)
$i=1;
while($row = mysqli_fetch_array($result))
{
echo " <div id='{$i}'>";
echo "<div class='tutorName'>" . $row['field1'] . "</div>";
echo "<div class='tutorPrice'>" . $row['field2'] . "</div>";
echo "<div class='tutorInstitution'>" . $row['field3'] . "</div>";
echo "<div class='tutorLocale'>" . $row['field4'] . "</div>";
echo "<div class='tutorPhone'>" . $row['field5'] . "</div>";
echo "</div>";
$i++;
}