PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mhenke
Forum Newbie
Posts: 21 Joined: Thu Jan 27, 2005 2:20 am
Post
by mhenke » 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?
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>";
mhenke
Forum Newbie
Posts: 21 Joined: Thu Jan 27, 2005 2:20 am
Post
by mhenke » Thu Jan 27, 2005 8:11 am
Yes I did that search too and found the same. My question is, how do I fit that code with mine? I need to use: glob("$img", GLOB_BRACE) as $image to produce a filled table... Anyone?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 27, 2005 8:33 am
your counting logic has errors in it. Specifically the if involving count at 4
mhenke
Forum Newbie
Posts: 21 Joined: Thu Jan 27, 2005 2:20 am
Post
by mhenke » Thu Jan 27, 2005 8:49 am
I guess there are errors as my code doesn't produce what I need ; )
Does anyone know how to produce the needed code using:
glob("$img", GLOB_BRACE) as $image
This should return all images with a certain name in a dir, formatted in the described table...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 27, 2005 8:51 am
the code posted does not use braces in the file pattern you are searching for. Maybe this is a problem?
mhenke
Forum Newbie
Posts: 21 Joined: Thu Jan 27, 2005 2:20 am
Post
by mhenke » Thu Jan 27, 2005 9:29 am
My code works fine, the only problem is that the table isn't generated properly. I need it to be generated like this:
image | image | image |
link | link | link |
break (tr) and repeat after an x amount of colums (3 here)
image | image | image |
link | link | link |
etc
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 27, 2005 9:44 am
I know I've posted how to do that several times.. I'll see if I can find the post (I always have trouble finding it)
in the mean time, I can tell you it involves using the modulo operator.
mhenke
Forum Newbie
Posts: 21 Joined: Thu Jan 27, 2005 2:20 am
Post
by mhenke » Thu Jan 27, 2005 9:57 am
THX looking forward to it. Been playing with modular/loops within loops for hours now : (
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 27, 2005 11:07 am
viewtopic.php?t=25105
PHP & MySQL formatting problem
finally found it.. I had to perform backend sql queries to find it..
I have too high a post rate
mhenke
Forum Newbie
Posts: 21 Joined: Thu Jan 27, 2005 2:20 am
Post
by mhenke » Thu Jan 27, 2005 11:54 am
THX!!!! Gonna play with this now, am sure it'll be fun : )