+ Reply to Thread
Results 1 to 5 of 5

 

Thread: PHP pass variable to include within include statement?

  1. #1
    accelerator's Avatar
    Online shopping rocks!

    Status
    Offline
    Join Date
    Nov 2004
    Location
    England
    Posts
    3,008
    Thanks
    54
    Thanked 180 Times in 161 Posts


    Hi All

    I have the following include file:

    <?php include("inc-select-merchants-by-keyphrase.php"); ?>

    Currently, I set a $KeyphraseAds variable for it at the top of my php page, to get merchants for the relevant keyphrase, and it displays a table of merchant results.

    However, this only allows one table of results on a page, and I would sometimes like to display multiple tables of results, i.e. use the include file more than once, but set a different $KeyphraseAds each time.

    Is there a way of setting an include specific variable, maybe within the include statement itself, to allow me to use the same include multiple times on a page but each time displaying different keyphrase results?

    I guess what I'm asking is, is there a way to send a variable to a specific instance of a php include?

    Many thanks

    Accelerator

  2. #2
    Registered User

    Status
    Offline
    Join Date
    Nov 2005
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sounds like you need to create an array with all the different keywords you want then a For or While Loop which will loop through all the keywords you want and include the appropriate files you want.

    Do a google search for "php array" and "php for loop"
    I don't like hidden campaigns unless i can see them

    Golf Gear: www.golfguy.co.uk | Mobile Content: www.topdogtones.com | Children's Toys: www.toyhound.co.uk

  3. #3
    Registered User

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    661
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I guess what I'm asking is, is there a way to send a variable to a specific instance of a php include?
    Can't you just reassign $keyphrase a new value just prior to each include?
    eg
    PHP Code:
    $keyphrase 'ipod';
    include(
    "inc-select-merchants-by-keyphrase.php");
    .....
    some more code.......;
    $keyphrase 'headphones';
    include(
    "inc-select-merchants-by-keyphrase.php"); 

  4. #4
    aka Antony

    Status
    Offline
    Join Date
    Mar 2005
    Location
    Bristol
    Posts
    531
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sounds like you need to make the include into a function

    Put the include statement at the start of your page

    In the include, wrap it in a function

    function merchant_table($KeyphraseAds)
    {
    //all the content of your original include here
    }

    then in the main body just call the function when you want the results

    merchant_table("ipod");

    //other stuff maybe

    merchant_table("shoes");

    etc

  5. #5
    accelerator's Avatar
    Online shopping rocks!

    Status
    Offline
    Join Date
    Nov 2004
    Location
    England
    Posts
    3,008
    Thanks
    54
    Thanked 180 Times in 161 Posts
    Agreed, a php function would be the way to do this.

    Thanks everyone.

    Rgds

+ Reply to Thread


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Including a PHP include within a PHP include ??
    By madstock in forum Programming
    Replies: 3
    Last Post: 17-12-03, 10:00 PM
  2. Php Include
    By scifind in forum Programming
    Replies: 5
    Last Post: 14-08-03, 06:01 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2