Jump to content

[SOLVED] every fifth entry create a break


dennismonsewicz

Recommended Posts

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;
	}

Link to comment
Share on other sites

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
	}

Link to comment
Share on other sites

this is what it looks like in FF:

 

14mvvgx.jpg

 

In IE:

 

11rrurq.jpg

 

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>';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.