MySQL result to HTML table (I know it must be simple, but...
Posted: Thu Jan 27, 2005 2:22 am
I'm trying to create an HTML table like this, data comes from MySQL:
<table>
<tr>
<td>image1</td>
<td>image2</td>
<td>image3</td>
<td>image4</td>
</tr>
<tr>
<td>link</td>
<td>link</td>
<td>link</td>
<td>link</td>
</tr>
<tr>
<td>image5</td>
<td>image6</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>link</td>
<td>link</td>
<td> </td>
<td> </td>
</tr>
</table>
I need to use this loop: foreach (glob("$img", GLOB_BRACE) as $image). I now have this, but it doesn't format the table as I need. Who can help me?
<table>
<tr>
<td>image1</td>
<td>image2</td>
<td>image3</td>
<td>image4</td>
</tr>
<tr>
<td>link</td>
<td>link</td>
<td>link</td>
<td>link</td>
</tr>
<tr>
<td>image5</td>
<td>image6</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>link</td>
<td>link</td>
<td> </td>
<td> </td>
</tr>
</table>
I need to use this loop: foreach (glob("$img", GLOB_BRACE) as $image). I now have this, but it doesn't format the table as I need. Who can help me?
Code: Select all
$id = $_SESSIONї'id'];
$path = "a/";
$img = $path . $id . "_" . "*" . ".jpg";
$count = 0;
$count2 = 0;
echo "<table cellpadding="0" cellspacing="5"><tr>";
foreach (glob("$img", GLOB_BRACE) as $image) {
$count++;
list($w, $h) = getimagesize($image);
$image2 = str_replace('a/', 's/', $image);
$image3 = str_replace('a/', '', $image);
echo "<td class="td2" align="center">";
echo "<img src="$image2" border="0" onClick="MM_openBrWindow('showpic.php?img=$image3','','status=yes, width=$w, height=$h')">";
echo "</td>";
if($count == 4){
echo "</tr><tr>";
foreach (glob("$img", GLOB_BRACE) as $image) {
$image4 = str_replace('a/', 's/', $image);
$count2++;
echo "<td class="td2" align="center">";
echo "$image4";
echo "</td>";
if($count2 == 4){
echo "</tr><tr>";
}
}
} if($count == 4){
echo "</tr><tr>";
}
}
}
echo "</tr></table>";