Jump to content

Archived

This topic is now archived and is closed to further replies.

webref.eu

Send variable to specific instance of an include file

Recommended 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

Share this post


Link to post
Share on other sites
Maybe it would be better for you to write a function and then call the function in your script as needed.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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
[code]
<?php

function date_today($date_today){

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

echo $date;

}
?>
[/code]

call the function

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

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

?>

[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.