Hello,
I've to display results of a query in a html table with 5 columns.
If results are i.e. 10 it should display a 2 rows table but if they're 13 it'd display 3 rows, the last with two cell empty.
any ideas or tip to do that?
I use this code but it display only one result and not all...
Where am I in wrong?
Thank you
// Recupera Users
$query = mysql_query("SELECT * FROM Users WHERE Status='Attivo' ORDER BY Id DESC LIMIT 10") or die(mysql_error());
while ($row = mysql_fetch_array($query)) {
// Recupera Foto
$query2 = mysql_query("SELECT * FROM Pictures WHERE User='$row[Id]' LIMIT 1") or die(mysql_error());
while ($row2 = mysql_fetch_array($query2)) {
//$rs[] = $row2['Url'];
$rs = array (array (
"name" => $row['Nome'],
"foto" => $row2['Url'],
));
}
}
$columns = 4;
$id = 0;
print ("<table>\r\n");
foreach ($rs as $record) {
if ($id % $columns == 0) {
print ("\t<tr>\r\n");
}
print ("\t\t<td> <img src=\"pictures/$record[foto]\" width=\"90\" height=\"150\" alt=\"Novita\" border=\"0\" /></td>\r\n");
if ($id % $columns == $columns - 1) {
print ("\t</tr>\r\n");
} $id++;
}
$id--;
if ($id % $columns != $columns - 1) {
$colspan = $columns - ($id % $columns) - 1;
print ("\t\t<td colspan='$colspan'> </td>\r\n");
print ("\t</tr>\r\n");
}
print ("</table>\r\n");