Hi all,
I am having quite some trouble with doing a certain task in php that im sure someone would know how to do it.
To start, I want to have my script create a table for every 12 keys in an array.
Here is the beginning of the code:
if (strpos($addon, "gallery")){
$gallery_filename = explode("|", $row_2['gallery_filename']);
$gallery_desc = explode("|", $row_2['gallery_desc']);
$photo_count = $row_2['photo_count'];
$arraycount = count($gallery_filename);
$gallery_filename
and $gallery_desc
are in an array.
WHAT I WANT TO DO is for every 12 keys found in the array it would create the following...
$table = <table id=\"gallery_desc\" width=\"700\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td align=\"center\" width=\"33%\"><img src=\"images/".$gallery_filename[0]."\" alt=\"".$gallery_desc[0]."\" vspace=\"10px\" height=\"75px\" /></td>
<td align=\"center\"><img src=\"images/".$gallery_filename[1]."\" alt=\"".$gallery_desc[1]."\" vspace=\"10px\" height=\"75px\" /></td>
<td align=\"center\"><img src=\"images/".$gallery_filename[2]."\" alt=\"".$gallery_desc[2]."\" vspace=\"10px\" height=\"75px\" /></td>
</tr>
<tr>
<td valign=\"top\" width=\"33%\">".$gallery_desc[0]."</td>
<td valign=\"top\" >".$gallery_desc[1]."</td>
<td valign=\"top\" >".$gallery_desc[2]."</td>
</tr>
<tr>
<td width=\"34%\"><img src=\"images/".$gallery_filename[3]."\" alt=\"".$gallery_desc[3]."\" vspace=\"10px\" height=\"75px\" /></td>
<td><img src=\"images/".$gallery_filename[4]."\" alt=\"".$gallery_desc[4]."\" vspace=\"10px\" height=\"75px\" /></td>
<td><img src=\"images/".$gallery_filename[5]."\" alt=\"".$gallery_desc[5]."\" vspace=\"10px\" height=\"75px\" /></td>
</tr>
<tr>
<td>".$gallery_desc[3]."</td>
<td>".$gallery_desc[4]."</td>
<td>".$gallery_desc[5]."</td>
</tr>
<tr>
<td><img src=\"images/".$gallery_filename[6]."\" alt=\"".$gallery_desc[6]."\" vspace=\"10px\" height=\"75px\" /></td>
<td><img src=\"images/".$gallery_filename[7]."\" alt=\"".$gallery_desc[7]."\" vspace=\"10px\" height=\"75px\" /></td>
<td><img src=\"images/".$gallery_filename[8]."\" alt=\"".$gallery_desc[8]."\" vspace=\"10px\" height=\"75px\" /></td>
</tr>
<tr>
<td>".$gallery_desc[6]."</td>
<td>".$gallery_desc[7]."</td>
<td>".$gallery_desc[8]."</td>
</tr>
<tr>
<td><img src=\"images/".$gallery_filename[9]."\" alt=\"".$gallery_desc[9]."\" vspace=\"10px\" height=\"75px\" /></td>
<td><img src=\"images/".$gallery_filename[10]."\" alt=\"".$gallery_desc[10]."\" vspace=\"10px\" height=\"75px\" /></td>
<td><img src=\"images/".$gallery_filename[11]."\" alt=\"".$gallery_desc[11]."\" vspace=\"10px\" height=\"75px\" /></td>
</tr>
<tr>
<td>".$gallery_desc[9]."</td>
<td>".$gallery_desc[10]."</td>
<td>".$gallery_desc[11]."</td>
</tr>
</table>"
so if there are more than 12 keys it would create another table with the corresponding keys 12 - 23 and than 24-33. But if there are not more than say 12 keys it would stop at the first table.
For now I am using this do this: if ($arraycount>0) {//$table="table here"}
and than if ($arraycount>11) {//$table.="table here"}
.
Instead of doing this over and over again would there be a way to do this with either while()
or foreach()
.
I am sorry if this doesn't make much sense, I can tryt o explain it more clearly if needed. Thanks for any help at all.