News:

Wondering if this will always be free?  See why free is better.

Main Menu

PHP While Loop!?

Started by ziycon, May 18, 2012, 07:24:03 AM

Previous topic - Next topic

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?


$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];
}

Herman's Mixen

global variable is $linkarray is used before its defined
Met vriendelijke groet, The Burglar!

 House Mixes | Mixcloud | Any Intelligent fool can make things bigger, more complex, and more violent.
It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Albert Einstein

Former Godfather of our dutch community ;)

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:
$level = $linkArray[$level][5];

To:
echo $linkArray[$level][5];
$level--;


It outputs ok.

Herman's Mixen

 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
Met vriendelijke groet, The Burglar!

 House Mixes | Mixcloud | Any Intelligent fool can make things bigger, more complex, and more violent.
It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Albert Einstein

Former Godfather of our dutch community ;)

ziycon

Maybe this might make more sense, I cleaned it up to remove non relevant 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];
}

Herman's Mixen

now only $breadcrumbNav aint defined... but parsed good ;)

line 16 gives the error not used before defined anyway


$breadcrumbNav = $linkArray[$level][1].$breadcrumbNav;
Met vriendelijke groet, The Burglar!

 House Mixes | Mixcloud | Any Intelligent fool can make things bigger, more complex, and more violent.
It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Albert Einstein

Former Godfather of our dutch community ;)

ziycon

Sorry I'm having a forgetful day, it was one of the lines I removed, here is the proper code.


$breadcrumbNav = '';
$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];
}


It seems that its timing out on the last line of the while loop: $level = $linkArray[$level][5];

Herman's Mixen

parsed ok without errors so it good ;)

no time out but check your configuratios apache/php/mysql can be horrible sometimes :P

what are you using for development ?
Met vriendelijke groet, The Burglar!

 House Mixes | Mixcloud | Any Intelligent fool can make things bigger, more complex, and more violent.
It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Albert Einstein

Former Godfather of our dutch community ;)

ziycon

Got it working, it was my logic with the while loop and the array. Thanks for your help. :)

Herman's Mixen

Met vriendelijke groet, The Burglar!

 House Mixes | Mixcloud | Any Intelligent fool can make things bigger, more complex, and more violent.
It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Albert Einstein

Former Godfather of our dutch community ;)

Advertisement: