Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

how do I carry variables from one file to another


NCR2000

Recommended Posts

Im trying to carry 3 variable from index.php to boxes.php

 

Variables are

$cornerleft

$cornerright

$cornerrightleft

 

 

snippet index.php (where the variables are defined)

the original code starts at line 40 of index.php

<?php echo "<link rel=\"stylesheet\" type=\"text/css\" href=\""; 

if ($cPath==21)
{
echo "stylesheet21.css";
$cornerleft = 'infobox/21cornerleft.gif';
$cornerright = 'infobox/21cornerright.gif';
$cornerrightleft = 'infobox/21cornerrightleft.gif';
}

elseif ($cPath==28)
{
echo "stylesheet28.css";
$cornerleft = 'infobox/28cornerleft.gif';
$cornerright = 'infobox/28cornerright.gif';
$cornerrightleft = 'infobox/28cornerrightleft.gif';
}

elseif ($cPath==29)
{
echo "stylesheet29.css";
$cornerleft = 'infobox/29cornerleft.gif';
$cornerright = 'infobox/29cornerright.gif';
$cornerrightleft = 'infobox/29cornerrightleft.gif';
}

elseif ($cPath==30)
{
echo "stylesheet30.css";
$cornerleft = 'infobox/30cornerleft.gif';
$cornerright = 'infobox/30cornerright.gif';
$cornerrightleft = 'infobox/30cornerrightleft.gif';
}

elseif ($cPath==31)
{
echo "stylesheet31.css";
$cornerleft = 'infobox/31cornerleft.gif';
$cornerright = 'infobox/31cornerright.gif';
$cornerrightleft = 'infobox/31cornerrightleft.gif';
}
else
{
echo "stylesheet.css";
$cornerleft = 'infobox/cornerleft.gif';
$cornerright = 'infobox/cornerright.gif';
$cornerrightleft = 'infobox/cornerrightleft.gif';
}

echo "\">";

?>

 

 

snippet of boxes.php (where the variables will be used)

the original code in boxes.php starts at line 100

if ($left_corner == true) {
       $left_corner = tep_image(DIR_WS_IMAGES . $cornerleft);
     } else {
       $left_corner = tep_image(DIR_WS_IMAGES . $cornerrightleft);
     }

 

 

Just for anyone wondering whats going on here...

I am setting up a site where the client wants the color scheme and images to change dependant on what category of products they are in. All of this would be possible through the stylesheet except the boxes.php file links directly to the images.... So I had to add the 3 variables above..

 

BUT i don't know how to carry those 3 variables from the index.php file over to the boxes.php file in order to use them.

 

can someone help me out here?

Link to comment
Share on other sites

Im trying to carry 3 variable from index.php to boxes.php

 

Variables are

$cornerleft

$cornerright

$cornerrightleft

snippet  index.php  (where the variables are defined)

the original code starts at line 40 of index.php

<?php echo "<link rel=\"stylesheet\" type=\"text/css\" href=\""; 

if ($cPath==21)
{
echo "stylesheet21.css";
$cornerleft = 'infobox/21cornerleft.gif';
$cornerright = 'infobox/21cornerright.gif';
$cornerrightleft = 'infobox/21cornerrightleft.gif';
}

elseif ($cPath==28)
{
echo "stylesheet28.css";
$cornerleft = 'infobox/28cornerleft.gif';
$cornerright = 'infobox/28cornerright.gif';
$cornerrightleft = 'infobox/28cornerrightleft.gif';
}

elseif ($cPath==29)
{
echo "stylesheet29.css";
$cornerleft = 'infobox/29cornerleft.gif';
$cornerright = 'infobox/29cornerright.gif';
$cornerrightleft = 'infobox/29cornerrightleft.gif';
}

elseif ($cPath==30)
{
echo "stylesheet30.css";
$cornerleft = 'infobox/30cornerleft.gif';
$cornerright = 'infobox/30cornerright.gif';
$cornerrightleft = 'infobox/30cornerrightleft.gif';
}

elseif ($cPath==31)
{
echo "stylesheet31.css";
$cornerleft = 'infobox/31cornerleft.gif';
$cornerright = 'infobox/31cornerright.gif';
$cornerrightleft = 'infobox/31cornerrightleft.gif';
}
else
{
echo "stylesheet.css";
$cornerleft = 'infobox/cornerleft.gif';
$cornerright = 'infobox/cornerright.gif';
$cornerrightleft = 'infobox/cornerrightleft.gif';
}

echo "\">";

?>

snippet of  boxes.php  (where the variables will be used)

the original code in boxes.php starts at line 100

if ($left_corner == true) {
? ? ? ?$left_corner = tep_image(DIR_WS_IMAGES . $cornerleft);
? ? ?} else {
? ? ? ?$left_corner = tep_image(DIR_WS_IMAGES . $cornerrightleft);
? ? ?}

Just for anyone wondering whats going on here...

I am setting up a site where the client wants the color scheme and images to change dependant on what category of products they are in.  All of this would be possible through the stylesheet  except the boxes.php file links directly to the images.... So I had to add the 3 variables above..

 

BUT  i don't know how to carry those 3 variables from the index.php file over to the boxes.php file in order to use them.

 

can someone help me out here?

 

you declare those variables as global in the function which executes :

 

function infoBoxHeading($contents, $left_corner = true, $right_corner = true, $right_arrow = false, $direct_output = true) {

 

global $cornerleft, $cornerright, $cornerrightleft;

 

if ($left_corner == true) {

$left_corner = tep_image(DIR_WS_IMAGES . $cornerleft);

} else {

$left_corner = tep_image(DIR_WS_IMAGES . $cornerrightleft);

}

Treasurer MFC

Link to comment
Share on other sites

you declare those variables as global in the function which executes :

 

    function infoBoxHeading($contents, $left_corner = true, $right_corner = true, $right_arrow = false, $direct_output = true) {

 

global $cornerleft, $cornerright, $cornerrightleft;

 

if ($left_corner == true) {

        $left_corner = tep_image(DIR_WS_IMAGES . $cornerleft);

      } else {

        $left_corner = tep_image(DIR_WS_IMAGES . $cornerrightleft);

      }

 

Yeah, but if the variables are defined in the index.php file don't I somehow have to pass those onto the boxes.php file before I can declare them?

Link to comment
Share on other sites

easiest would probably be to set it up to register in session.

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

  • 2 months later...

How would you do this, if you didnt already have a function?

 

I basically need to assign a particular value to a variable called $paul but only when the user is on a particular page, if he visits the checkout page that variable is pulled and displayed, however if he visits his account page the variable is wiped and a new value assigned to it.

 

Basically I need to know how to assign a value to a global variable, how to create that variable and where i can call it, do I need to create a function?

 

thnx

Paul

Link to comment
Share on other sites

How would you do this, if you didnt already have a function?

 

I basically need to assign a particular value to a variable called $paul but only when the user is on a particular page, if he visits the checkout page that variable is pulled and displayed, however if he visits his account page the variable is wiped and a new value assigned to it.

 

Basically I need to know how to assign a value to a global variable, how to create that variable and where i can call it, do I need to create a function?

 

thnx

Paul

 

in the upper php part of all checkout files, session variable are declared, unregistered for new use and filled ... you can steal code there!

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

thnx for the quick reply, this is what i have so far, I need to set the URL so im doing this.

 

I have a site and after the user visits the checkout page, he can continue shopping, he could have arrived at the checkout page two ways.

Pressing the add to cart button from a product listiing.

pressing the add to cart button from a product_info page.

 

However when he is finished I want him to return to the product listing (even if it is on its 6 page) no matter what, he wont want to go back to the product info page, he just bought the product

 

So i set up a little Global variable called $host

 

This is at the beggining of the product listing page

$host = $_SERVER['REQUEST_URI'];

 

In my general functions file i have

function pauls_link() {
global $host;
$rlink = $host;
echo $rlink;
}

 

and in my checkout page I have

<?php pauls_link();?>

Just so i can see whats going on for now, I will eventually link it to the continue shopping button

 

Now I have also set up the function to echo in the header of each page.

on the index page, it shows the url its on.

When I goto the product_info page it shows nothing, shouldnt it show the last URL, why is not stored in the variable?

 

Also why does the last product listing URL it visited not stay in the variable?

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...