| | |
Math Problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
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.
I know that's very confusing, but hopefully someone can understand and give me some mathematical help.
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.
php Syntax (Toggle Plain Text)
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.
"We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." - Robert Wilensky
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:
Hope that helps to answer your question.
php Syntax (Toggle Plain Text)
$loop=0; while ($loop<=100) { $val=$loop/10; if ($val==round($val)) { echo ($i % ($amount / 10) == 0) ? "<div class=\"load\"></div>" : ""; } $loop+=1; }
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Well, your solution didn't work for me, but it got me thinking and now my code works. 
Soon I'm going to post it in the Web Developer's Lounge. It'll be something everyone wants.

Soon I'm going to post it in the Web Developer's Lounge. It'll be something everyone wants.
"We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." - Robert Wilensky
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:
wouldn't work.
Can you post the rest of your code?
And I don't see why this code:
•
•
•
•
php Syntax (Toggle Plain Text)
echo ($i % ($amount / 10) == 0) ? "<div class=\"load\"></div>" : "";
Can you post the rest of your code?
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
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
I'll be posting this project soon. I know you'll like it R0b
Last edited by MVied; Oct 4th, 2008 at 11:13 pm.
"We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." - Robert Wilensky
![]() |
Similar Threads
- Problem with do-while loop (C++)
- Math problem in C (C)
- A discrete math problem (Computer Science)
- Math/computerscience Log Problem- Helpppp (Computer Science)
- C++ problem (C++)
- Decimal Problem In C (C)
- Please help me out, need help (C)
- first math class in uni (Geeks' Lounge)
Other Threads in the PHP Forum
- Previous Thread: 30-11-1999 Help Me
- Next Thread: Adding Advanced Ranking Surveys
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend






