Results 1 to 3 of 3

Thread: Layering a PHP?

  1. #1
    Join Date
    Jun 2005
    Location
    Canada
    Posts
    68
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Layering a PHP?

    The goal here is to have a new group of featured products change when either a page is refreshed or a visitor returns to the site. What I have done is created six product galleries and then placed them in a random call as follows:
    Code:
    <?php
    srand((float) microtime() * 10000000);
    $input = array(
    '<?php include ("gallery-insert.php">; ?>',
    '<?php include ("gallery-insert2.php">; ?>',
    '<?php include ("gallery-insert3.php">; ?>',
    '< php include ("gallery-insert4.php">; ?>',
    '<?php include ("gallery-insert5.php">; ?>',
    '<?php include ("gallery-insert6.php">; ?>',
    );
    $rand_key = array_rand($input);
    echo $input[$rand_key] . "\n";
    ?>
    When I call the php files individually they work fine, but when I call from the "galleryrotator.php" file I simply get a ( ; ?>) where the file should appear.
    Is it not possible to achieve this with php or is there something I am missing in the code which is clearly possible since I am just beginning to understand php a wee bit better.
    Thanks for your help.
    DM

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Ah, at the moment you're not actually including them, just echoing them - that's why it doesn't work. Rewrite the code like this:

    PHP Code:
    <?php
    srand
    ((float) microtime() * 10000000);
    $input = array(
    "gallery-insert.php",
    "gallery-insert2.php",
    "gallery-insert3.php",
    "gallery-insert4.php",
    "gallery-insert5.php",
    "gallery-insert6.php",
    );
    $rand_key array_rand($input);
    include 
    $input[$rand_key]; echo "\n";
    ?>
    I've tested this and know it works, good luck

    Remember that you're already within a <?php ?> block and so you don't need to type this for every item in the array, you just need the file names and then use include instead of echo.

  3. The Following User Says Thank You to Schmoopy For This Useful Post:

    Diversions (02-06-2009)

  4. #3
    Join Date
    Jun 2005
    Location
    Canada
    Posts
    68
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    Just when I thought I was getting the hang of php, I find I am not even close. It works a charm to be sure! Thanks so much Schmoopy.

    My regards

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •