Jump to content


Photo

i need an if statement


  • Please log in to reply
3 replies to this topic

#1 skeg0

skeg0
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 March 2006 - 12:00 PM

im wondering if anyone can help me as im new to php.

I have a database driven php webpage that contains a menu at the top of each page called "top_template.php".. when a link is clicked to load a new page, it automatically reloads this "top_template" with a --- require "top_template.php"; --- command in the main body part of the page. however, there will be some times when i need to load up a different menu at the top depending on what the previous page was. so i was wondering if php has commands in it that will allow for an IF statement along the following lines:

if the referer (the page link that referred to this new page) == "menu1.php" THEN
require "menu2.php" ELSE require "menu1.php"

or

if menu2 is visible THEN require "menu2" ELSE
require menu1

it is just the direct syntax of these statements i need as it is written above, if anyone could help me i would be extremely grateful!!

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 27 March 2006 - 12:14 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]if the referer (the page link that referred to this new page) == "menu1.php" THEN
require "menu2.php" ELSE require "menu1.php"

or

if menu2 is visible THEN require "menu2" ELSE
require menu1[/quote]



if ($referer == 'menu1.php') 
       $req_menu = 'menu2.php';
else
       $req_menu = 'menu1.php';

//OR

$req_menu = ($referer == 'menu1.php') ? 'menu2.php' : 'menu1.php';

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 skeg0

skeg0
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 March 2006 - 12:22 PM

[!--quoteo(post=358851:date=Mar 27 2006, 01:14 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Mar 27 2006, 01:14 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
if ($referer == 'menu1.php') 
       $req_menu = 'menu2.php';
else
       $req_menu = 'menu1.php';

//OR

$req_menu = ($referer == 'menu1.php') ? 'menu2.php' : 'menu1.php';
[/quote]


thanks very much.. do i have to define these variables somewhere? the $referer and $req_menu or are they already known by php?

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 27 March 2006 - 05:42 PM

$req_menu is defined in the above code.

$referer will need to be defined by your program (prob from processing $_SERVER['HTTP_REFERER'] variable).
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users