Need help with repeating/looping in PHP
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 '</开发者_StackOverflow社区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:
And what I want would look like this:
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());
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());
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.
精彩评论