Hi all
I am calling a function inside a while loop and if certain criteria is met, the function is called again within itself. The while loop is below:
while ($row = mysql_fetch_array($result)) {
$sectionid = $row['sectionid'];
$title = $row['name'];
$url = $row['url']; // friendly url string e.g. about-us or contact-us etc
$childof = $row['childof']; // the Parent record sectionid
$securl = hasChildren($SECTIONS, $url, $childof);
// echo $securl;
echo "\t\t\t<li><a class=\"notactive\" href=\"$securl\" title=\"$title\">$title </a></li>\n";
}
mysql_free_result($result);
The hasChildren function is as follows:
function hasChildren($SECTIONS, $passedurl, $childof) {
if ($childof < 7) {
$securl = $SECTIONS['url'][$childof-1] ."/". $passedurl; // build URL based on passed CHILDOF
} else {
$securl = $SECTIONS['url'][$childof-1] ."/". $passedurl; // build URL based on passed CHILDOF
$childof = $SECTIONS['childof'][$childof-1]; // next parent
hasChildren($SECTIONS, $securl, $childof);
}
//return $securl;
echo $securl . "<br />";
exit();
}
Now my problem is this. When I echo $securl at the end of the function, it returns the URL string as expected:
/url-one/url-two/url-three (for example)
However, when I echo the $securl value AFTER the function call in my WHILE loop, the first part of the string (e.g. /url-one) is removed from the variable.
Can anyone see why this is?? I have been pulling my hair out for hours!!
Thanks for reading