I've got the folllowing function which works... almost. With the else part added, no matter what link is selected the error page is returned. Without it the function works as expected with the appropriate file included and variables echoed, depending on the link selected.
The values are stored in a 2 dimensional array.Code:<?php function createContent($arr) { $id = $_GET['id']; for ($i = 0; $i < count($arr); $i++) { if (!isset($id)) { // default page $inc = "includes/{$arr[0][0]}.php"; $x = $arr[0][1]; $y = $arr[0][2]; $z = $arr[0][3]; } elseif ($id == $arr[$i][0]) { // link is selected $inc = "includes/{$arr[$i][0]}.php"; $x = $arr[$i][1]; $y = $arr[$i][2]; $z = $arr[$i][3]; } else { // invalid URL $inc = 'includes/error.php'; $x = 'Error'; $y = ''; $z = ''; header('HTTP/1.0 404 Not Found'); } $pg = basename($_SERVER['PHP_SELF']); // create links $link = " <li><a href=\"{$pg}?id={$arr[$i][0]}\">{$arr[$i][1]}</a></li>\n"; if ($id == $arr[$i][0] || !isset($id) && strstr($link, $arr[0][0])) { $link = str_replace($link, " <li id=\"current\">{$arr[$i][1]}</li>\n", $link); } $links[] = $link; } $vars = array($inc,$x,$y,$z,$links); return $vars; } ?>
I suspect the problem may lie in the condition for the elseif part but don't know how to fix this.Code:$arr = array(array('home', 'Home Page', 'a aa aaa.', 'z, zz, zzz,'), array( 'about', 'About Us' etc...



Reply With Quote


Bookmarks