在PHP中重复/循环需要帮助

时间:2011-05-22 15:13:54

标签: php mysql loops rows

我有这个PHP和HTML块:

<table width="57%" border="0" class="tabela_master" id="aps-cat">
<tr>
<?php    
while ($row = $db->sql_fetchrow($result_1))
{
      echo '<td width="33%" rowspan="12" align="center"><img src="../images/' . $row['picture'] . '" /></td>';
      echo '<td width="20%" align="right" class="tabela_master" style="font-weight: bold">Emri / Mbiemri:</td>';
      echo '<td width="1%">&nbsp;</td>';
      echo '<td width="46%" class="tabela_master">' . $row['firstname'] . " " . $row['lastname'] . '</td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold">Gjinia:</td>';
      echo '<td>&nbsp;</td>';
      echo '<td class="tabela_master">' . $row['gender'] . '</td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold">Datelindja:</td>';
      echo '<td>&nbsp;</td>';
      echo '<td class="tabela_master">' . $row['birthday'] . '</td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold">Adresa / Lokacioni:</td>';
      echo '<td>&nbsp;</td>';
      echo '<td class="tabela_master">' . $row['location'] . '</td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold">Telefoni:</td>';
      echo '<td>&nbsp;</td>';
      echo '<td class="tabela_master">' . $row['telephone'] . '</td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold">Email adresa:</td>';
      echo '<td>&nbsp;</td>';
      echo '<td class="tabela_master">' . $row['email'] . '</td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold">Interesi:</td>';
      echo '<td>&nbsp;</td>';
      echo '<td class="tabela_master">' . $row['occupation'] . '</td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold">&nbsp;</td>';
      echo '<td>&nbsp;</td>';
      echo '<td class="tabela_master">&nbsp;</td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold">&nbsp;</td>';
      echo '<td>&nbsp;</td>';
      echo '<td class="tabela_master">&nbsp;</td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold">&nbsp;</td>';
      echo '<td>&nbsp;</td>';
      echo '<td class="tabela_master">&nbsp;</td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold">&nbsp;</td>';
      echo '<td>&nbsp;</td>';
      echo '<td class="tabela_master">&nbsp;</td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold">&nbsp;</td>';
      echo '<td>&nbsp;</td>';
      echo '<td class="tabela_master">&nbsp;</td>';
}
//$db->sql_freeresult($result_1);
?>
</tr>
</table>

现在我想要的是页面中显示的多个记录。网站目前看起来像这样: Current look

我想要的是这样的: Wanted look

所以我的表格将提供我的MySQL查询的所有结果,如下所示:

$sql_1 = 'SELECT id, firstname, lastname, birthday, location, occupation, gender, telephone, email, picture 
          FROM pinkmoon_users ORDER BY `id` DESC LIMIT 1';
$result_1 = $db->sql_query($sql_1) or die($db->sql_error());

2 个答案:

答案 0 :(得分:3)

删除SQL语句中的LIMIT 1

$sql_1 = 'SELECT id, firstname, lastname, birthday, location, occupation, gender, telephone, email, picture 
          FROM pinkmoon_users ORDER BY `id` DESC ';
$result_1 = $db->sql_query($sql_1) or die($db->sql_error());

答案 1 :(得分:0)

您的查询仅检索数据库中的最后一条记录。如果您需要更多内容,则应将LIMIT 1更改为(例如)LIMIT 10或完全删除限制约束。