Can we include one php file multiple times?

I have a php-file called kal_test.php which gives a value to the variable $vbl. This variable is needed in the file called kal_generator.php which produces a table from that variable [I'll spare you the details]. It goes like this:

[kal_test.php]


[kal_test.php]


This will give the following result:

//here comes the header

 // table created with $vbl = "14/09/2011"
  blablabla
thisworks
thisworks
//here should the second table be and also the rest of the page [footer], this is completely missing

What am I doing wrong? Thanks!

The include function will allow you to include the same file multiple times so you can use it within a loop.,This will include the product.php file as many times as it loops through the $products array, but if this was using a include_once function it will only display the product.php file once.,The include_once function is exactly the same as the include function except it will limit the file to be used once.,The include function is used in PHP when you want to include a file within the current process. It takes one argument which will be a string to the file path you want to include.

include 'header.php';





include 'footer.php';

include_once 'main_page.php';

foreach[$products as $product] {
   
   include 'product.php';
}

foreach[$products as $product] {
   
   include_once 'product.php';
}


Suggestion : 2

The function can only be defined once, and so you want to include this outside of the loop.,Is it possible to have an include function several times on the same page pointing to the same php file?,It is perfectly feasible to use the include function more than once. Any inline code in the included file will be run as though the included file were run. This can sometimes cause unpredictable results and requires certain amount of care, particularly with variables., Maybe post some of the code in the images.php file so we can see what is being included? We may be able to give you some pointers...

sure its basically just an image swapper with some javascript:

;

;

;

;



   

   function changeImage[ref] {

      var img = [document.all] ? document.all.imageSample : document.getElementById['imageSample'];

      var myImage = [];

      var imagea = "";
      var imageb = "";
      var imagec = "";
      var imaged = "";

      

      myImage['red'] = new Image[];

      myImage['red'].src = imagea;

      

      myImage['green'] = new Image[];

      
      myImage['green'].src = imageb;

      myImage['blue'] = new Image[];
      
      
      myImage['blue'].src = imagec;

      myImage['black'] = new Image[];

      myImage['black'].src = imaged;

If the code in the pictures.php file IS in a class, then yes, you will need to create a new object, but it depends on the name of the class [as opposed to the file]. For example, if the pictures.php file contains the following line:

then results.php would need to create a new PictureManager object like so:

$pictures = new PictureManager[];

Here is the code for results.php

Chủ Đề