DeanWhitehouse Posted May 19, 2008 Share Posted May 19, 2008 How can i put a < br > after every 4 amount of entry's What i need is to start a new line every after four entry's are echoed, this is my code <?php $query = "SELECT image_id, image_name, image_link, folder_name,img_time FROM `darkflame_gallery`"; $result = mysql_query($query) or die("Error:" . mysql_error()); if (mysql_num_rows($result) > 0) { echo "<table class='news'><tr><th>Image Gallery</th></tr><tr><td id='new'><br><br />"; while ($row = mysql_fetch_assoc($result)) { echo "<b>".$row['img_time']."</b>"; ?> - <a href="?image_id=<?php echo $row['image_id']; ?>"><?php echo $row['image_name']; ?></a><br><?php echo nl2br(stripslashes($cont));; ?><br><br> <?php } } ?> Link to comment https://forums.phpfreaks.com/topic/106334-solved-ampampltbrampampgt-after-every-certain-amount-of-entrys/ Share on other sites More sharing options...
947740 Posted May 19, 2008 Share Posted May 19, 2008 Through in a variable, such as $i. Increase it every time through the loop. If it is 4, reset the variable and break the line. Link to comment https://forums.phpfreaks.com/topic/106334-solved-ampampltbrampampgt-after-every-certain-amount-of-entrys/#findComment-544948 Share on other sites More sharing options...
DeanWhitehouse Posted May 19, 2008 Author Share Posted May 19, 2008 ok, slightly lost on how to do it, but if i do that how will it know when to start a new line? someone gave me this code, but i can't get it to work properly now <?php $query = "SELECT image_id, image_name, image_link, folder_name,img_time FROM `darkflame_gallery`"; $result = mysql_query($query) or die("Error:" . mysql_error()); if (mysql_num_rows($result) > 0) { ?> <table border="1"> <?php $loop = 4; $loop1 = 4; while($row=mysql_fetch_array($result)){ // Start looping table row if ($loop == 4) { echo "<tr>"; } $toecho1 .= '<td><a href="?image_id='.$row['image_id'].'">Details</a></td><td> </td>'; $toecho .= '<td><a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="150px" /></a></td><td> </td>'; if ($loop == 4) { echo "</tr>"; $loop=0; } } if (substr($toecho, -5) != "</tr>") { $toecho .= "</tr>"; } echo $toecho; echo $toecho1; } ?> </table> <?php if (mysql_num_rows($result) < 1) { echo "No Images To Display"; } ?> Link to comment https://forums.phpfreaks.com/topic/106334-solved-ampampltbrampampgt-after-every-certain-amount-of-entrys/#findComment-544950 Share on other sites More sharing options...
BlueSkyIS Posted May 19, 2008 Share Posted May 19, 2008 Throw in a variable, such as $i. Increase it every time through the loop. If it is 4, reset the variable and break the line. $i = 0; while ($something) { if ($i == 4) { $i = 0; // reset variable echo "<BR>"; // break the line } // something here... $i++; // increase $i each time through the loop } Link to comment https://forums.phpfreaks.com/topic/106334-solved-ampampltbrampampgt-after-every-certain-amount-of-entrys/#findComment-544972 Share on other sites More sharing options...
phpzone Posted May 19, 2008 Share Posted May 19, 2008 OR <?php $array = range("a","z"); for ( $i = 0; $i < count($array); ++$i ) { print ($i + 1) % 4 == 0 ? "$i -- Matched Fourth!!!<br />" : ''; } ?> I use ($i + 1) because array is zero based. Link to comment https://forums.phpfreaks.com/topic/106334-solved-ampampltbrampampgt-after-every-certain-amount-of-entrys/#findComment-544984 Share on other sites More sharing options...
DeanWhitehouse Posted May 19, 2008 Author Share Posted May 19, 2008 ok, i tried this <?php $i = 0; while (mysql_num_rows($result) > 0) { if ($i == 4) { $i = 0; // reset variable echo "<BR>"; // break the line } echo "<b>".$row['img_time']."</b>"; ?> - <a href="?image_id=<?php echo $row['image_id']; ?>"><?php echo $row['image_name']; ?></a><br><?php echo nl2br(stripslashes($cont));; ?><br><br> <?php $i++; // increase $i each time through the loop } ?> and this doesn't show my results, and also keeps loading, i have had to stop the script twice as it crashed my browser. this is the code surrounding it <?php $query = "SELECT image_id, image_name, image_link, folder_name,img_time FROM `darkflame_gallery`"; $result = mysql_query($query) or die("Error:" . mysql_error()); $i = 0; while (mysql_num_rows($result) > 0) { if ($i == 4) { $i = 0; // reset variable echo "<BR>"; // break the line } echo "<b>".$row['img_time']."</b>"; ?> - <a href="?image_id=<?php echo $row['image_id']; ?>"><?php echo $row['image_name']; ?></a><br><?php echo nl2br(stripslashes($cont));; ?><br><br> <?php $i++; // increase $i each time through the loop } ?> Link to comment https://forums.phpfreaks.com/topic/106334-solved-ampampltbrampampgt-after-every-certain-amount-of-entrys/#findComment-544989 Share on other sites More sharing options...
BlueSkyIS Posted May 19, 2008 Share Posted May 19, 2008 because while (mysql_num_rows($result) > 0) { // will always be true. an infinite loop. i think you want: while ($row = mysql_fetch_assoc($result)) { Link to comment https://forums.phpfreaks.com/topic/106334-solved-ampampltbrampampgt-after-every-certain-amount-of-entrys/#findComment-544993 Share on other sites More sharing options...
DeanWhitehouse Posted May 19, 2008 Author Share Posted May 19, 2008 how can i get it to show line like this |title| name1|name2|name3| image1|image2|image3| i tried this //No ID passed to page, display user list: $query = "SELECT image_id, image_name, image_link, folder_name,img_time FROM `darkflame_gallery`"; $result = mysql_query($query) or die("Error:" . mysql_error()); $i = 0; ?> <table><tr><td> <?php while ($row = mysql_fetch_assoc($result)) { if ($i == 4) { $i = 0; // reset variable echo "<BR>"; // break the line } echo "<b>".$row['img_time']."</b></td></tr><tr><td>"; ?><a href="?image_id=<?php echo $row['image_id']; ?>"><?php echo $row['image_name']; ?></a> <?php $i++; // increase $i each time through the loop } ?> </td></tr></table> do i need to have two seperate echo's? or two while loops? Link to comment https://forums.phpfreaks.com/topic/106334-solved-ampampltbrampampgt-after-every-certain-amount-of-entrys/#findComment-545009 Share on other sites More sharing options...
DeanWhitehouse Posted May 19, 2008 Author Share Posted May 19, 2008 can anyone help?? Link to comment https://forums.phpfreaks.com/topic/106334-solved-ampampltbrampampgt-after-every-certain-amount-of-entrys/#findComment-545044 Share on other sites More sharing options...
947740 Posted May 19, 2008 Share Posted May 19, 2008 You could use a line break in the <td>. Echo the name, <br />, and then the image. Link to comment https://forums.phpfreaks.com/topic/106334-solved-ampampltbrampampgt-after-every-certain-amount-of-entrys/#findComment-545047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.