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

发布于 2024-11-08 15:33:55 字数 4274 浏览 0 评论 0原文

我有这个 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());

I have this block of PHP and 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%"> </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> </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> </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> </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> </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> </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> </td>';
      echo '<td class="tabela_master">' . $row['occupation'] . '</td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold"> </td>';
      echo '<td> </td>';
      echo '<td class="tabela_master"> </td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold"> </td>';
      echo '<td> </td>';
      echo '<td class="tabela_master"> </td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold"> </td>';
      echo '<td> </td>';
      echo '<td class="tabela_master"> </td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold"> </td>';
      echo '<td> </td>';
      echo '<td class="tabela_master"> </td>';
      echo '</tr>';
      echo '<tr>';
      echo '<td align="right" class="tabela_master" style="font-weight: bold"> </td>';
      echo '<td> </td>';
      echo '<td class="tabela_master"> </td>';
}
//$db->sql_freeresult($result_1);
?>
</tr>
</table>

Now what I want is multiple records shown in the page. The web currently looks like this:
Current look

And what I want would look like this:
Wanted look

So my table would provide all my results from my MySQL query which looks like this:

$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());

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自由范儿 2024-11-15 15:33:55

删除 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());

Remove the LIMIT 1 in your SQL statement

$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());
许仙没带伞 2024-11-15 15:33:55

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

Your query retrieves only the last record from the database. If you want more, you should change the LIMIT 1 to (for example) LIMIT 10 or remove the limit contraint entirely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文