Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Junior Member
    Join Date
    Oct 2003
    Posts
    5
    Member #
    3457
    I have this example PHP file:

    PHP Code:
    if($do == "search" or $dosearch == "yes")
    {
     
    $subaction "search";
     
    $dosearch "yes";
     include(
    "$path/search.php"); 
    }
    elseif(
    $do == "archives")
    {
     include(
    "$path/show_archives.php"); 
    }
    else
    {
     include(
    "$path/show_news.php"); 

    But how do I apply those variable into it?
    PHP Code:
    $number "7";
    $category "1"
    I've tried like below but it doesn't work:

    PHP Code:
    if($do == "search" or $dosearch == "yes")
    {
     
    $subaction "search";
     
    $dosearch "yes";
     include(
    "$path/search.php"); 
    }
    elseif(
    $do == "archives")
    {
     include(
    "$path/show_archives.php"); 
    }
    else
    {
     include(
    "$path/show_news.php"); 
    }

    $number "7";
    $category "1"
    Do I have to use elseif again? Please help, I'm totally new to PHP, thanks a lot.

  2.  

  3. #2
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    Both of them are after everything is said and done with ifs. If these variables are going to be used in the included files, then you should place them on top of your ifs.
    There and Back Again :Ogre:

  4. #3
    Junior Member
    Join Date
    Oct 2003
    Posts
    5
    Member #
    3457
    I'm not sure what do you mean. These variables are not in the "included" files. Could you show me the code please?

  5. #4
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    What I meant was that if your search.php or show_archives.php or show_news.php needs to $number or $category variables, then they will need to be set before you include the files, as the following code:

    PHP Code:
    $number "7";
    $category "1";
    if(
    $do == "search" or $dosearch == "yes")
    {
     
    $subaction "search";
     
    $dosearch "yes";
     include(
    "$path/search.php"); 
    }
    elseif(
    $do == "archives")
    {
     include(
    "$path/show_archives.php"); 
    }
    else
    {
     include(
    "$path/show_news.php"); 

    Since I'm not sure about the purpose of the variables, I can't say much other than what I have indicated.
    There and Back Again :Ogre:

  6. #5
    Junior Member
    Join Date
    Oct 2003
    Posts
    5
    Member #
    3457
    wow, works like a charm, I guess I have to pick up some PHP books to learn.

    Thanks a bunch.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:31 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com