cordoprod Posted July 13, 2008 Share Posted July 13, 2008 Hi. I have a db and i get the username, in profile images. I fetch the row and then i replace the username with the path to his profile image. What i want to do is to break the tr and add a new row when it's 3 images. Like this image1 image2 image3 image4 image5 image6 or else it just like this image1 image2 image3 image4 image5 image6 $c = 3; foreach($rows['visitor'] as $Key => $Value) { if(!($Key % $c)) echo "</tr><tr>"; echo "<td width=\"10%\">"; if(file_exists("images/pg/".$rows['visitor']."_tiny.jpg")) { echo "<a href=\"?s=user&nick=".$rows['visitor']."\"><img class=\"$class\" src=\"images/pg/".$rows['visitor']."_tiny.jpg\" width=\"60\" /></a><br>"; } else { echo "<a href=\"?s=user&nick=".$rows['visitor']."\"><img class=\"$class\" src=\"images/pg/no_picture_tiny.jpg\" width=\"60\" /></a><br>"; } echo "</td> <td width=\"90%\"><span class=\"$class2\"><a href=\"?s=user&nick=".$rows['visitor']."\">".$rows['visitor']."</a></span><br />"; time_elapsed_done($rows['tid']); echo "</td>"; } if(!($Key % $c)) echo "</tr>"; When i use that code i get: invalid argument supplied for foreach Quote Link to comment https://forums.phpfreaks.com/topic/114512-solved-new-row-automatically/ Share on other sites More sharing options...
DeanWhitehouse Posted July 13, 2008 Share Posted July 13, 2008 something like this? while($rows = mysql_fetch_array($sql)) { if($i == 3){echo "<tr><td> </td></tr>"; } echo $rows['visitors']; $i++; } i think that should work, with some tweaking Quote Link to comment https://forums.phpfreaks.com/topic/114512-solved-new-row-automatically/#findComment-588849 Share on other sites More sharing options...
cordoprod Posted July 13, 2008 Author Share Posted July 13, 2008 something like this? while($rows = mysql_fetch_array($sql)) { if($i == 3){echo "<tr><td> </td></tr>"; } echo $rows['visitors']; $i++; } i think that should work, with some tweaking Almost, if it's more than 6 entries then it just continues on the second row. 1 2 3 4 5 6 7 8 9 10 Understand? Quote Link to comment https://forums.phpfreaks.com/topic/114512-solved-new-row-automatically/#findComment-588853 Share on other sites More sharing options...
DeanWhitehouse Posted July 13, 2008 Share Posted July 13, 2008 ok, try this while($rows = mysql_fetch_array($sql)) { if($i == 3){echo "<tr><td> </td></tr>"; $i = 0;} echo $rows['visitors']; $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/114512-solved-new-row-automatically/#findComment-588856 Share on other sites More sharing options...
cordoprod Posted July 13, 2008 Author Share Posted July 13, 2008 ok, try this while($rows = mysql_fetch_array($sql)) { if($i == 3){echo "<tr><td> </td></tr>"; $i = 0;} echo $rows['visitors']; $i++; } Excellent, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/114512-solved-new-row-automatically/#findComment-588898 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.