PDA

View Full Version : If and include



mtran
06-06-2007, 03:19 AM
I want to have different left nav for differernt areas of the site, for example if the pages are about company, I use the following,... but it doesn't work:



<?php
if($navL.indexOf("company")!==-1) include($_SERVER['DOCUMENT_ROOT'].'/site/navL_company.php'); ?>


At the beginning of each page in the Company area, I put:
$navL="company_about"
or $navL="company_locations"....

What's wrong? Thanks!

alexjewell
06-06-2007, 03:42 PM
Eh, there's easier ways to do this. For example, add this onto the url: ?company=yes.

Then:



if(@$_GET['company']){
$co = $_GET['company'];
if($co == 'yes'){
include('site/navL_company.php');}
else if($co == 'no'){
include('site/navL.php');}
else{include('site/navL.php');}}
else{include('site/navL.php');}

thetestingsite
06-06-2007, 03:42 PM
It is because PHP does not have a built-in function called indexOf (that's in Javascript). Anyways, you could try using strstr to find out if the word "company" has been passed like so:



<?php
if(strstr($navL, 'company')) {
include($_SERVER['DOCUMENT_ROOT'].'/site/navL_company.php');
}
?>


Hope this helps.

//EDIT: sorry alex, cross posted.