MDanz Posted January 7, 2011 Share Posted January 7, 2011 I want to loop the below code until $grade=80, is the code below correct <?php include "grade.php"; $getgrade = new Grade(); // create an instance of the class(Grade) echo "<ul id='navigation'>"; for($grade=0;$grade<80;$grade+10){ $max = $grade+9; //get max grade for that grading bracket, e.g. 10-19% echo "<li><a href='#'>$grade-$max%</a> <ul><li>"; $getgrade->results($grade+9); // call the method(results) in grade.php echo "</li></ul> </li>"; } echo "</ul>"; ?> the page isn't loading when i try it so i'm guessing i got it wrong.. Quote Link to comment https://forums.phpfreaks.com/topic/223633-help-with-loop/ Share on other sites More sharing options...
denno020 Posted January 7, 2011 Share Posted January 7, 2011 That for loop will run 7 times I think.. You are incrementing the counter by 10 each time.. What do you mean the page isn't loading? Have you got error reporting turned on for your php? If you're using an online host, and can't edit the php.ini file, then you need to explicitly turn on error reporting. See here: http://php.net/manual/en/function.error-reporting.php Hope that helps. Denno Quote Link to comment https://forums.phpfreaks.com/topic/223633-help-with-loop/#findComment-1156007 Share on other sites More sharing options...
MDanz Posted January 7, 2011 Author Share Posted January 7, 2011 actually the page is taking long to load because of the code... is it because i am repeatedly calling the method? Quote Link to comment https://forums.phpfreaks.com/topic/223633-help-with-loop/#findComment-1156017 Share on other sites More sharing options...
denno020 Posted January 7, 2011 Share Posted January 7, 2011 Possibly. I don't know how but the results() function is.. Denno Quote Link to comment https://forums.phpfreaks.com/topic/223633-help-with-loop/#findComment-1156019 Share on other sites More sharing options...
DavidAM Posted January 7, 2011 Share Posted January 7, 2011 The page is running forever. You are not actually incrementing the loop variable. Try this for the loop: for($grade = 0; $grade < 80; $grade += 10){ Quote Link to comment https://forums.phpfreaks.com/topic/223633-help-with-loop/#findComment-1156040 Share on other sites More sharing options...
denno020 Posted January 7, 2011 Share Posted January 7, 2011 The page is running forever. You are not actually incrementing the loop variable. Try this for the loop: for($grade = 0; $grade < 80; $grade += 10){ Oh good call! Denno Quote Link to comment https://forums.phpfreaks.com/topic/223633-help-with-loop/#findComment-1156041 Share on other sites More sharing options...
MDanz Posted January 7, 2011 Author Share Posted January 7, 2011 thanks Quote Link to comment https://forums.phpfreaks.com/topic/223633-help-with-loop/#findComment-1156049 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.