Cloud9247 Posted July 10, 2006 Share Posted July 10, 2006 I have been developing my graphics site lately, and I have run into a problem. Currently I am setting up a 100x100 avatars page, and I am using mysql_fetch_array. I want it to have in each row of avatars, 4 avatars per row. and I am currently using tables for this, so can someone help me get it to where every 4 rows it inserts a '<tr>' and '</tr>', so I could get more rows? Link to comment https://forums.phpfreaks.com/topic/14210-table-with-fetch/ Share on other sites More sharing options...
willfitch Posted July 10, 2006 Share Posted July 10, 2006 Have you tried testing this in you loop?[code=php:0]<?php$i=0;while ($row = $result->fetch_object()) { if ($i == 3) { // 4 $content .= '<tr>'; $i = 0; }}[/code] Link to comment https://forums.phpfreaks.com/topic/14210-table-with-fetch/#findComment-55732 Share on other sites More sharing options...
Cloud9247 Posted July 10, 2006 Author Share Posted July 10, 2006 no, I haven't. But I don't really know how to implement that either. Link to comment https://forums.phpfreaks.com/topic/14210-table-with-fetch/#findComment-55756 Share on other sites More sharing options...
.josh Posted July 10, 2006 Share Posted July 10, 2006 [code]<?php$sql = "some query";$result = mysql_query($sql);$i = 0;echo "<table><tr>";while ($list = mysql_fetch_array($result)) { echo "<td>{$list['columnamehere']}</td>"; if ($i == 3) { echo "</tr><tr>"; $i = 0; } $i++;}echo "</tr></table>"?>[/code] Link to comment https://forums.phpfreaks.com/topic/14210-table-with-fetch/#findComment-55762 Share on other sites More sharing options...
Cloud9247 Posted July 10, 2006 Author Share Posted July 10, 2006 [code]<?phpecho $top1.'Avatars'.$top2.$body1;echo '<table id= "avatars"><tr>';$i= 0; $sqll= "SELECT userid, id, clicks, username, submitted, name, credits, comments, series, imgurl, active FROM avatars WHERE active='1' ORDER BY `id` DESC LIMIT $from, $max_results"; // LIMIT $from, $max_results$rss= mysql_query( $sqll, $connection );while($row= mysql_fetch_array( $rss )) {$dwn= "return false;";echo '<td id= "avi"><a href= "http://hayalkarga.com/designs.php?viewavatar='.$row['id'].'"><img src= "'.$row['imgurl'].'" id= "graphic" alt= "'.$row['name'].'" oncontextmenu="return false"></a></td>'; if ($i == 3) { echo "</tr><tr>"; $i = 0; } $i++;}echo '</tr></table>';echo $body2.$foot1.$foot2;[/code]comes out as: http://hayalkarga.com/designs.php?designs=avatarsIt prints out 4 on the first row, but only 3 on the others. Can someone help me fix this? Link to comment https://forums.phpfreaks.com/topic/14210-table-with-fetch/#findComment-55795 Share on other sites More sharing options...
ShogunWarrior Posted July 10, 2006 Share Posted July 10, 2006 That's because after setting $i=0 it then adds one before starting the loop.Replace $i==3 with $i==4 and before the loop replace $i=0; with $i=1; Link to comment https://forums.phpfreaks.com/topic/14210-table-with-fetch/#findComment-55802 Share on other sites More sharing options...
Cloud9247 Posted July 10, 2006 Author Share Posted July 10, 2006 Actually, I just figured out to replace it with $i= -1, which works fine, thanks for your help everyone! Link to comment https://forums.phpfreaks.com/topic/14210-table-with-fetch/#findComment-55806 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.