Jump to content

menre

New Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by menre

  1. menre

    PHP Includes

    Oh yes, that solves the problem. Now it is working without errors. Thanks
  2. menre

    PHP Includes

    Hello, Thanks for your response. But I tried fixing that error myself before by adding the closing ')' to it in three places. It did not help. That brings an error message on the line with the final "}" of the code. the code below is what I presently have. <?php function create_nav($active) { $nav = ''; if ($active == 'home') { $nav .= '<li class="active">';} else $nav .= '<li>';} $nav .= '<a href="#">Home</a></li>'; if ($active == 'about') { $nav .= '<li class="active">'; } else { $nav .= '<li>'; } $nav .= '<a href="#">About</a></li>'; if ($active == 'contact') { $nav .= '<li class="active">'; } else { $nav .= '<li>'; } $nav .= '<a href="#">Contact</a></li>'; return $nav; } echo create_nav('home'); ?> But the last "}" above the line "echo create_nav('home');" shows an error. Any idea how to fix that? Thanks, Menre
  3. menre

    PHP Includes

    Hello, I am kind of wandering how you got the PHP code in your post to work? I tried it by having all you said on one page. But when I ran it on the server, I got some nasty error messages. Such as 'Undefined variable nav on line 22', 'Undefined variable active on line 24', 'Undefined variable active on line 25'. My full page code is placed below. <!doctype html> <html lang="en-US"> <meta charset="utf-8"> <title>Creating a highlighted link</title> <style type="text/css"> a {color: black;} body.page1 a.page1 {color: red;} body.page2 a.page2 {color: red;} body.page3 a.page3 {color: red;} </style> </head> <body> <ul class="nav"> <li><a class="page1" href="page1.php">Page one</a></li> <li><a class="page2" href="page2.php">Page two</a></li> <li><a class="page3" href="page3.php">Page three</a></li> </ul> <?php function create_nav($active) { $nav = ''; if ($active == 'home' { $nav .= '<li class="active">';} else $nav .= '<li>';} $nav .= '<a href="#">Home</a></li>'; if ($active == 'about' { $nav .= '<li class="active">'; } else { $nav .= '<li>'; } $nav .= '<a href="#">About</a></li>'; if ($active == 'contact' { $nav .= '<li class="active">'; } else { $nav .= '<li>'; } $nav .= '<a href="#">Contact</a></li>'; return $nav; } echo create_nav('home'); ?> </body> </html> I will really appreciate some feedback from you. Thanks in advance. Menre
×
×
  • Create New...