Results 1 to 4 of 4

Thread: Layers of PHP?

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

    Default Layers of PHP?

    I am trying to build a website in php on wamp server and I am running into a problem but not sure what it is.

    1. I am pulling a php page with <?php include(thedirectory.php); ?> which is fine I am not getting any errors.

    2. within "thedirectory.php" file I am pulling a graphics file (hilighted in red) such as the following
    <?php
    srand((float) microtime() * 10000000);
    $input = array(
    '<tr><td width="20%" align="center"><a href="jump.php/CaseStudy" title="Case StudyA"><b>Case Study A</b></a></td><td width="15%" align="center"><?php include("starrating.php"); ?></td><td width="65%" align="left">short description</td><tr>',
    );
    $rand_keys = array_rand($input, 5);
    echo $input[$rand_keys[0]] . "\n";
    echo $input[$rand_keys[1]] . "\n";
    echo $input[$rand_keys[2]] . "\n";
    echo $input[$rand_keys[3]] . "\n";
    echo $input[$rand_keys[4]] . "\n";
    echo $input[$rand_keys[5]] . "\n";
    ?>
    I am not now getting any errors. The starrating.php file is a five line file and pulls the graphic from the images folder which is definitely in there.

    Because I am pretty new to the PHP language I am not sure if
    A. this can be done, and
    B. if the process outlined above is not correct then I require a fix.
    Of course, if the code seems okay then I will have to keep looking for what is likely a pretty silly oversight.

    Many thanks
    D

  2. #2
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 9 Times in 9 Posts

    Default

    I'm not entirely sure what you are trying to do with array_rand, but you only have one element in your array.

    It's likely that you can do what you want, but without knowing what this is, it's difficult to say.

    Also, it's helpful when reading posted php code, to post it between [php] ... [/php] tags or [code] ... [/code] tags for non-php code.

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

    Default

    Your name and my incessant need to babble.

    Okay...the actual php page is rather extensive and has 40 lines in it so I took the liberty of truncating it since thedirectory.php page is loading fine.
    My problem comes in no images being pulled in the <?php include("starrating.php"); ?> when thedirectory.php page loads. The <td></td> is simply blank without error codes or error icons.
    Hopefully that helps to clarify me a wee bit.
    This page is actually randomly loaded and that is why the use of array_rand I think. Still finding my way.

  4. #4
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 9 Times in 9 Posts

    Default

    The problem is that you are echoing the php code, ie: attempting to send it to the browser. php is processed server-side and therefore won't work the way you are trying it.

    It's a still a little hard to give a better recommendation without seeing what's happening (or supposed to be happening). I wouldn't worry about posting 40 lines of code - that's actually not that extensive.

    It would also help to see what starrating.php is doing.

    This page is actually randomly loaded and that is why the use of array_rand I think.
    No. array_rand is used to pull a random value or values from an array. It has nothing to do with how the page is loaded. The idea is that the array would contain several elements, and array_rand would randomly select them. Since you array has only one element, array_rand is accomplishing nothing.

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
  •