dezkit Posted November 4, 2008 Share Posted November 4, 2008 Hi guys, how do I make it so that whenever 3 Entries get echo'd a new <tr> appears? <table width="600" style="height:146px;" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="100" style="height:60px;"><p style="margin:0 0 0 0"><a href=""><img style="margin:0 0 0 0;" src="images/example.jpg" width="83" height="60" alt="" border="0"></a></p></td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/131404-solved-next-row-after-3-mysql-entries-have-been-echod/ Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 Create a variable, increment it for each DB table row, and if it's 3, reset it and echo </tr><tr>. Link to comment https://forums.phpfreaks.com/topic/131404-solved-next-row-after-3-mysql-entries-have-been-echod/#findComment-682425 Share on other sites More sharing options...
dezkit Posted November 4, 2008 Author Share Posted November 4, 2008 Gah, are there any tutorials on this? Google doesn't help Link to comment https://forums.phpfreaks.com/topic/131404-solved-next-row-after-3-mysql-entries-have-been-echod/#findComment-682426 Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 Show your code. You're only showing part of it. Show the part with the loop. Link to comment https://forums.phpfreaks.com/topic/131404-solved-next-row-after-3-mysql-entries-have-been-echod/#findComment-682427 Share on other sites More sharing options...
dezkit Posted November 4, 2008 Author Share Posted November 4, 2008 <?php include("./config.php"); $result = mysql_query("SELECT * FROM gallery") or die(mysql_error()); echo "<table width=\"600\" style=\"height:146px;\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"; while($row = mysql_fetch_array( $result )) { echo "<td width=\"100\" style=\"height:60px;\"><p style=\"margin:0 0 0 0\"><a href=\"#\"><img style=\"margin:0 0 0 0;\" src=\"./uploads/" . echo $row['thumburl'] . "\" width=\"83\" height=\"60\" alt=\"\" border=\"0\"></a></p></td>"; } echo "</table>"; After 3 rows get <td>'s gtt echo'd i want a new <tr>!! Link to comment https://forums.phpfreaks.com/topic/131404-solved-next-row-after-3-mysql-entries-have-been-echod/#findComment-682431 Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 echo "<table width=\"600\" style=\"height:146px;\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"; $rows = 1; while($row = mysql_fetch_array( $result )) { if ($rows==1) echo "<tr>"; echo "<td width=\"100\" style=\"height:60px;\"><p style=\"margin:0 0 0 0\"><a href=\"#\"><img style=\"margin:0 0 0 0;\" src=\"./uploads/" . echo $row['thumburl'] . "\" width=\"83\" height=\"60\" alt=\"\" border=\"0\"></a></p></td>"; if ($rows==3){ echo "</tr>"; $rows = 0; } $rows++; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/131404-solved-next-row-after-3-mysql-entries-have-been-echod/#findComment-682433 Share on other sites More sharing options...
Michdd Posted November 4, 2008 Share Posted November 4, 2008 Not sure if this is what you wanted... <?php include("./config.php"); $result = mysql_query("SELECT * FROM example") or die(mysql_error()); echo "<table width=\"600\" style=\"height:146px;\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"; $count = "0"; while($row = mysql_fetch_array( $result )) { $count++; echo "<td width=\"100\" style=\"height:60px;\"><p style=\"margin:0 0 0 0\"><a href=\"#\"><img style=\"margin:0 0 0 0;\" src=\"./uploads/" . echo $row['thumburl'] . "\" width=\"83\" height=\"60\" alt=\"\" border=\"0\"></a></p></td>"; if($count => "3"){ echo "</tr><tr>"; $count = "0"; } } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/131404-solved-next-row-after-3-mysql-entries-have-been-echod/#findComment-682434 Share on other sites More sharing options...
dezkit Posted November 4, 2008 Author Share Posted November 4, 2008 It says "Parse error: syntax error, unexpected T_ECHO in /home/cobi/public_html/gallery.php on line 85" Line85: echo "<td width=\"100\" style=\"height:60px;\"><p style=\"margin:0 0 0 0\"><a href=\"#\"><img style=\"margin:0 0 0 0;\" src=\"./uploads/" . echo $row['thumburl'] . "\" width=\"83\" height=\"60\" alt=\"\" border=\"0\"></a></p></td>"; Thanks, guys. Link to comment https://forums.phpfreaks.com/topic/131404-solved-next-row-after-3-mysql-entries-have-been-echod/#findComment-682438 Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 You have an extra echo in that line: echo "<td width=\"100\" style=\"height:60px;\"><p style=\"margin:0 0 0 0\"><a href=\"#\"><img style=\"margin:0 0 0 0;\" src=\"./uploads/" . $row['thumburl'] . "\" width=\"83\" height=\"60\" alt=\"\" border=\"0\"></a></p></td>"; Link to comment https://forums.phpfreaks.com/topic/131404-solved-next-row-after-3-mysql-entries-have-been-echod/#findComment-682441 Share on other sites More sharing options...
dezkit Posted November 4, 2008 Author Share Posted November 4, 2008 OMG! It works perfectly, THANKS SO MUCH <33 Link to comment https://forums.phpfreaks.com/topic/131404-solved-next-row-after-3-mysql-entries-have-been-echod/#findComment-682443 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.