使用sql表中的数据自动创建div

时间:2012-08-25 18:38:51

标签: php sql html

我正在尝试使用从SQL数据库获取的每个数据创建不同数据的重复div。我有代码创建div并使用正确的数据填充正确的字段,但我的代码将div嵌套在彼此之内。

<?php
$query = mysql_query("SELECT id, name, location, amountRequested FROM     fundable");

while ($temp = mysql_fetch_array($query)) {
echo "<div class='widgetLoan'>";
echo "<div class='title'><h6>".$temp['name']."</h6><span class='widgetLoanCat'>Category</span>";
echo "<div class='num'><a href='#' class='blueNum'>".$temp['amountRequested']."</a></div>";
echo "</div>";
}
?>

3 个答案:

答案 0 :(得分:3)

试试这个:

<?php
$query = mysql_query("SELECT id, name, location, amountRequested FROM     fundable");

while ($temp = mysql_fetch_array($query)) {
echo "<div class='widgetLoan'>";
echo "<div class='title'><h6>".$temp['name']."</h6><span class='widgetLoanCat'>Category</span></div>";
echo "<div class='num'><a href='#' class='blueNum'>".$temp['amountRequested']."</a></div>";
echo "</div>";
}
?>

答案 1 :(得分:1)

您忘记关闭</div>代码

变化

echo "<div class='title'><h6>".$temp['name']."</h6><span class='widgetLoanCat'>Category</span>";

echo "<div class='title'><h6>".$temp['name']."</h6><span class='widgetLoanCat'>Category</span></div>";

答案 2 :(得分:0)

您似乎错过了</div>代码。