0

我试图让我的代码显示多个 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>
4

2 回答 2

0

您的 $result 行真的在真实代码中被注释掉了吗?还是您只是为示例添加了该评论?如果它在您正在测试的代码中被注释掉,那么这可能就是问题所在。

于 2013-04-26T03:40:02.770 回答
0

你要这个?, 1 div 包装所有内容,如 table tr

$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++;
}
于 2013-04-26T03:41:12.727 回答