Hello, I thought up of a great way to build my online gallery but coding it in PHP is another story. I have no idea what to do, so I'll describe what I'm attempting and perhaps someone might be able to direct me. Something tells me the answer might have something to to with arrays:

  1. My online gallery has 5 sections. Each section is build from the same basic framework that is "gallery.php".

  2. The variables determining the sections are, for example: gallery.php?section=illustration

  3. Gallery.php contains the main code which generates the various galleries by using the data from the five different section files.

  4. Each section file contains the following data: Section description text and header and a list (an array?) of images to display in a table.

  5. In other words, the gallery.php code should echo the descriptive text from [illustration.php] AND generate an html table from the list/array in that file as well.

My question is really two-fold: how do I use the same file (illustration.php) to define two different variables

and

what functions do I use to generate a table with data provided in an external file's (illustration.php) list or array?

Sorry if I repeat myself, I'm trying to be as clear as possible!
Thanks 🙂

    to use the external file i suggest either using the include (); function. im not really sure what it is that you mean.

      Yes, I'm familiar with the include function but doesnt "include" target the entire file? How do I fetch specific parts of an external file?

      This is only part of my problem though. I still have no idea on how to generate a table (or table rows) from an array taken from the external file.

        I'm not certain that this is what you want but... to get out your array of info try the following.

        Make a file placing each member of the array on a new line with a line break.
        E.g.

        apples
        oranges
        pears

        Then read the file as below.

        <?php
        echo "<table border='2'>"; //borders on to see the table build

        //put in path to file
        $myarray=file("fruit.txt");

        foreach ($myarray as $value) {
        echo "<tr><td>";
        echo "Fruit: $value";
        echo "</td></tr>";
        }

        echo "</table>";

        ?>

        the foreach function only works in php4.

        You can set up the differnet parts of your pages and grab on a variable using include().

        include ($section_header.php);
        include ($section_body.php);
        include ($section_footer.php);

        etc.

        Hope this is the right idea for you

        Jon Bertsch

          Sorry, this isnt exactly what I wanted to do, but I'll find another way of doing it. It's getting more confusing with each new problem I encounter.

          But I'm still looking for answers regarding fetching different data from a same file.

          The easiest way to explain this:

          What if I had:

          <? include ($section_header);?>
          some html content or PHP content code
          <? include ($section_footer);?>

          Is there a way to have the header code and footer code reside in the same file?

            Write a Reply...