dennismonsewicz Posted April 1, 2008 Share Posted April 1, 2008 I need a way of checking to see if something equals a particular number, in my case 5, and every 5th entry create a new line. Any way to do this? echo '<table align=center border=0 width=650 cellpadding=4 cellspacing=0 class=imgtable> <tr> <td><u><b>Image</b></u></td> </tr> <tr> <td valign="top">'; //And we display the results while($result = mysql_fetch_array( $data )) { $kbsize = $result['size'] / 1024; //$name = str_replace($find, "<span class='yellowbg'>$find</span>", $result['name']); $size = str_replace($find, "<span class='yellowbg'>$find</span>", $kbsize); $type = str_replace($find, "<span class='yellowbg'>$find</span>", $result['type']); $categories = str_replace($find, "<span class='yellowbg'>$find</span>", $result['categories']); $id = $result['id']; $filecount = count($result['name']); $typenoimage = str_replace("image/", "", $type); if(count($result['name'] == 5)) { $br = "<br />"; } else { $br = ""; } echo '<img src="imageuploads/thumbs/' . $result['name'] . '" alt=' . $result['name'] . ' border=0>'; echo $br; } Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 1, 2008 Share Posted April 1, 2008 Setup a counter, increment the counter in the loop. Add an if statement which checks to see if the counter is at 5, if it is reset the counter and echo the a newline. Otherwise increment counter: echo '<table align=center border=0 width=650 cellpadding=4 cellspacing=0 class=imgtable> <tr> <td><u><b>Image</b></u></td> </tr> <tr> <td valign="top">'; //And we display the results $i = 0; // initialise counter while($result = mysql_fetch_array( $data )) { $kbsize = $result['size'] / 1024; //$name = str_replace($find, "<span class='yellowbg'>$find</span>", $result['name']); $size = str_replace($find, "<span class='yellowbg'>$find</span>", $kbsize); $type = str_replace($find, "<span class='yellowbg'>$find</span>", $result['type']); $categories = str_replace($find, "<span class='yellowbg'>$find</span>", $result['categories']); $id = $result['id']; $filecount = count($result['name']); $typenoimage = str_replace("image/", "", $type); echo '<img src="imageuploads/thumbs/' . $result['name'] . '" alt=' . $result['name'] . ' border=0>'; // check if $i is equal to 5, if it is echo line break and reset counter if($i == 5) { $br = "<br />"; $i = 0; // reset counter } else $i++; // increment counter } Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted April 1, 2008 Author Share Posted April 1, 2008 ok it only does it for the first row in Firefox but in IE it counts up to 6 then for the rest of the row they are all in one row Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted April 1, 2008 Author Share Posted April 1, 2008 this is what it looks like in FF: In IE: And here is my code : //And we display the results $i = 0; // initialise counter while($result = mysql_fetch_array( $data )) { $kbsize = $result['size'] / 1024; //$name = str_replace($find, "<span class='yellowbg'>$find</span>", $result['name']); $size = str_replace($find, "<span class='yellowbg'>$find</span>", $kbsize); $type = str_replace($find, "<span class='yellowbg'>$find</span>", $result['type']); $categories = str_replace($find, "<span class='yellowbg'>$find</span>", $result['categories']); $id = $result['id']; $filecount = count($result['name']); $typenoimage = str_replace("image/", "", $type); echo '<img src="imageuploads/thumbs/' . $result['name'] . '" alt=' . $result['name'] . ' border=0>'; if($i == 5) { echo "<br />"; $i = 0; // reset counter } else { $i++; // increment counter } // check if $i is equal to 5, if it is echo line break and reset counter } echo '</td> </tr> </table>'; Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 1, 2008 Share Posted April 1, 2008 Sorry, it is outputting 6 images because the counter starts at zero. If you only want 5 images per row change this line: if($i == 5) to if($i == 4) Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted April 1, 2008 Author Share Posted April 1, 2008 TOPIC SOLVED! Quote Link to comment 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.