Customizing SMF > SMF Coding Discussion
PHP While Loop!?
ziycon:
Maybe its due to me looking at the code so long I just can't see whats going on but can anyone tell me why the below code is timing out?
--- Code: ---$level = 1;
while($level >= 0) {
$breadcrumbNav = $linkArray[$level][1].$breadcrumbNav;
// $linkArray[$level][5] will always be less then the current value for $level but not always a concurrent decrement
$level = $linkArray[$level][5];
}
--- End code ---
The Burglar!:
global variable is $linkarray is used before its defined
ziycon:
Sorry, I should have said, everything is defined before hand, there is so much code I didn't post it all as I think its an issue with my logic in the while loop as if I change the below line:
--- Code: ---$level = $linkArray[$level][5];
--- End code ---
To:
--- Code: ---echo $linkArray[$level][5];
$level--;
--- End code ---
It outputs ok.
The Burglar!:
i debugged the code coz m lazy today... while ihave not full code cant make any sense out of it...the output is debugged oke anyway... got just 2 errors before the globals are defined before they are used :P
$breadcrumbNav
and
$linkArray
ziycon:
Maybe this might make more sense, I cleaned it up to remove non relevant code.
--- Code: ---$linkParent = array();
$currentPage = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$linkArray = self::getNavArray(); // returns an array of all available links on the site in the format (id, link_text, link, sequence, pages_to_display_on, parent)
for($i=0;$i<sizeof($linkArray);$i++) {
if(strstr($currentPage,$linkArray[$i][2]))
$linkParent = $linkArray[$i][5];
}
$level = $linkParent;
while($level >= 0) {
$breadcrumbNav = $linkArray[$level][1].$breadcrumbNav;
$level = $linkArray[$level][5];
}
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version