Okay, so I'm writing an application. In this application there is a drop down with the selections 10, 20, 30, and so on to 100. This drop down controls the amount of times a loop will occur. Basically, every time the application gets to a loop that is 10% of the total amount of loops, I want it to echo out a small line. On the user end this outputs a small block in a progress bar.

For example if you choose 10, then every loops it would output a block on the progress bar to give us 100%.

If you choose 20, every 2 loops it would output a block on the progress bar to give us 100%.

The easy way out would be to make a huge case select of if, elseif statement, but that's not what I want to do.

As an example, if you choose 10 ($amount = 10), it works correctly. $i is the increment of the loop.

echo ($i % ($amount / 10) == 0) ? "<div class=\"load\"></div>" : "";

I know that's very confusing, but hopefully someone can understand and give me some mathematical help. :P

I have had to do similar things in the past and I find division and rounding to be the answer. An example is as below:

$loop=0;
while ($loop<=100)
	{
	$val=$loop/10;
	if ($val==round($val))
		{
		echo ($i % ($amount / 10) == 0) ? "<div class=\"load\"></div>" : "";
		}
	$loop+=1;
	}

Hope that helps to answer your question.

Comments
Your response helped me solve my problem. Much thanks.

Well, your solution didn't work for me, but it got me thinking and now my code works. :D

Soon I'm going to post it in the Web Developer's Lounge. It'll be something everyone wants. ;)

I don't know if round would be necessary since 10, 20, 30..., 100 are all % 10 evenly. :-/

And I don't see why this code:

echo ($i % ($amount / 10) == 0) ? "<div class=\"load\"></div>" : "";

wouldn't work. :-/

Can you post the rest of your code?

Basically the problem was $i starting off as 0. This threw it off completely. I used $n to start as 1 and count (because I use the $i for more than just an increment).

I'll be posting this project soon. I know you'll like it R0b ;)

Comments
Sounds interesting
This question has already been answered. Start a new discussion instead.