为什么不是我的while循环获取mysql数据库条目并呈现它们如演示?谢谢:)。
<?php $djs_all_db = mysql_query("SELECT * FROM djs")
or die(mysql_error());
$djs_all_num = mysql_num_rows($djs_all_db);
while($djs_all = mysql_fetch_array( $djs_all_db )) {
if ($djs_all_num % "2") {
echo "<div class=\"row\">
<div class=\"column column-2\">
<img src=\"images/about/" . $djs['username'] . "-profile.png\" alt=\"Profile\" class=\"profile-image\"/>
<p class=\"float-left\"><strong>" . $djs['realname'] . "</strong></p>
<p class=\"float-right\"><a href=\"#\" title=\"\">" . $djs['position'] . "</a></p>
<div class=\"clear\"></div>
<p>" . $djs['biography'] . "</p>
</div>";
} else {
echo "<div class=\"column column-3\">
<img src=\"images/about/" . $djs['username'] . "-profile.png\" alt=\"Profile\" class=\"profile-image\"/>
<p class=\"float-left\"><strong>" . $djs['realname'] . "</strong></p>
<p class=\"float-right\"><a href=\"#\" title=\"\">" . $djs['position'] . "</a></p>
<div class=\"clear\"></div>
<p>" . $djs['biography'] . "</p>
</div></div>";
} }?>
答案 0 :(得分:3)
您的循环定义:$ djs_all - 在您的代码中使用:$ djs ['username'],将其更改为$ djs_all ['username']
答案 1 :(得分:0)
不知道这是不是你的问题,但是
if ($djs_all_num % "2") {
测试静态数字(表格中的条目数量),因此您将始终执行if
或else
部分。
另外,你循环一个djsall变量:
while($djs_all = mysql_fetch_array( $djs_all_db )) {
但是你试图从$ djs中访问字段:
<img src=\"images/about/" . $djs['username']