Spectre Posted July 15, 2009 Share Posted July 15, 2009 function tab($result){ while($tab = mysqli_fetch_assoc($result)) { tabrow($tab); } } function tabrow($row){ echo '<TR>'; echo '<td width="15"> </td>'; for($i = 1; $i<=4; $i++){ if($row[image] == "blank"){ $row[image] = 'image/achievement_locked.png'; } echo '<td><img src="'.$row[image].'" title="'.$row[alt_text].'"></td><td width="10"> </td>'; } echo'<td width="5"> </td>'; if($i%4==0){ echo'</tr>'; } } ?> <TABLE WIDTH="400" HEIGHT="450" ALIGN="center" STYLE="background-image: url('image/hutBK.png');"> <? tab($result); ?> <tr height="30"></tr> </table> <? Ok so there's my code snippet, i'm working on no sleep in 3 days (well other than an hour nap I managed) all i'm trying to do is make the table echo out in a 4 x 4 style (4 columns and 4 rows). But what it's doing is, echoing out the first thing 4 times, then new row, then 2nd thing 4 times and so on. I want it to show the first image, then 2nd, 3rd, 4th NEW ROW 5th 6th and so on, up to 16th and table ends... a little help please? Link to comment https://forums.phpfreaks.com/topic/166055-solved-help-functioned-table-not-behaving/ Share on other sites More sharing options...
KevinM1 Posted July 15, 2009 Share Posted July 15, 2009 function tab($result){ while($tab = mysqli_fetch_assoc($result)) { tabrow($tab); } } function tabrow($row){ echo '<TR>'; echo '<td width="15"> </td>'; for($i = 1; $i<=4; $i++){ if($row[image] == "blank"){ $row[image] = 'image/achievement_locked.png'; } echo '<td><img src="'.$row[image].'" title="'.$row[alt_text].'"></td><td width="10"> </td>'; } echo'<td width="5"> </td>'; if($i%4==0){ echo'</tr>'; } } ?> <TABLE WIDTH="400" HEIGHT="450" ALIGN="center" STYLE="background-image: url('image/hutBK.png');"> <? tab($result); ?> <tr height="30"></tr> </table> <? Ok so there's my code snippet, i'm working on no sleep in 3 days (well other than an hour nap I managed) all i'm trying to do is make the table echo out in a 4 x 4 style (4 columns and 4 rows). But what it's doing is, echoing out the first thing 4 times, then new row, then 2nd thing 4 times and so on. I want it to show the first image, then 2nd, 3rd, 4th NEW ROW 5th 6th and so on, up to 16th and table ends... a little help please? Something like the following should work: $count = 0; $table = "<table><tr>"; while($row = mysqli_fetch_assoc($result)) { if(($count % 4) == 0) { $table .= "</tr><tr>"; } if($row['image'] == 'blank') { $row['image'] = "image/achievement_locked.png"; } $table .= "<td><img src=\"{$row['image']}\" alt=\"{$row['alt_text']}\" /></td>"; ++$count; } $table .= "</tr></table>"; echo $table; Link to comment https://forums.phpfreaks.com/topic/166055-solved-help-functioned-table-not-behaving/#findComment-875747 Share on other sites More sharing options...
Spectre Posted July 15, 2009 Author Share Posted July 15, 2009 Used your way, with a few tweaks (as I'm adding in paging to it etc) and works fine ( I knew it'd be simple but my brain was just not seeing it). Thanks for the help lol, much appreciated, and I now know not to code on so little sleep as I keep trying to make something simple, overly complicated. Link to comment https://forums.phpfreaks.com/topic/166055-solved-help-functioned-table-not-behaving/#findComment-876032 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.