Jump to content


Photo

Send variable to specific instance of an include file


  • Please log in to reply
4 replies to this topic

#1 webref.eu

webref.eu
  • Members
  • PipPipPip
  • Advanced Member
  • 213 posts

Posted 02 September 2006 - 02:45 PM

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
WebRef.eu - Internet Marketing Resources

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 02 September 2006 - 03:09 PM

Maybe it would be better for you to write a function and then call the function in your script as needed.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 September 2006 - 03:40 PM

nope your have to use a function() then call that function on the page.

warning.

include more then a few times will give you problams always use a function and call that function from a .php page.

so you make the function on a page.php then you incude once that page and use the function as meny time as you need it.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 webref.eu

webref.eu
  • Members
  • PipPipPip
  • Advanced Member
  • 213 posts

Posted 02 September 2006 - 04:41 PM

Thanks guys. 

Do I write the function in it's own .php file?  If so, what is the syntax to include the function in the page? 

What is the syntax to call a function and send it a specific value of a variable at the same time? 

Many thanks
WebRef.eu - Internet Marketing Resources

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 September 2006 - 04:52 PM

function();// This is a function.

function me();// This is a function named me.

function var($var);//this is a function named var and got a varable to be used inside the function or outside the function.

return function name()/ / this is used to return a function within it self.

when you want a function to be seen from another page always include() that .php page then call the function() as shown below

good luck.

function.php
<?php

function date_today($date_today){

$date=date("d-m-y");

echo $date;

}
?>

call the function

<?php
//include the function
include("function.php");

// call the function throw the include.
function date_today($date_today);

?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users