co.ador Posted December 18, 2009 Share Posted December 18, 2009 supposing $currentpage= 2 $range = 3 what would be the final value for $x and output for the for loop? <?php for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++)?> Quote Link to comment https://forums.phpfreaks.com/topic/185554-what-would-be-the-results-for-this-for-loop/ Share on other sites More sharing options...
ngreenwood6 Posted December 18, 2009 Share Posted December 18, 2009 6 but it would only go to 5 Quote Link to comment https://forums.phpfreaks.com/topic/185554-what-would-be-the-results-for-this-for-loop/#findComment-979617 Share on other sites More sharing options...
mikesta707 Posted December 18, 2009 Share Posted December 18, 2009 The final result will be 5, and the loop will display whatever you have in its block 5 times Quote Link to comment https://forums.phpfreaks.com/topic/185554-what-would-be-the-results-for-this-for-loop/#findComment-979628 Share on other sites More sharing options...
co.ador Posted December 18, 2009 Author Share Posted December 18, 2009 I have been trying to figure out why if $currentpage is greater than 2 then the variable $strZipCode will pass empty? <?php $range=4; // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b >$x</b>] "; // if not current page... } else { // make it a link http_build_query( $strName,$strZipCode, $strState, $arrFoodTypes, $arrOfferings) echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x&strZipCode= ". $strZipCode . "'>$x</a> "; } // end else } // end if } ?> Quote Link to comment https://forums.phpfreaks.com/topic/185554-what-would-be-the-results-for-this-for-loop/#findComment-979651 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.