Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    quick array/variable question

    I've got a few pages with different searches on them and a main page where I want to aggregate them all using includes. I have one section that parses the search term, another section that puts the urls for the 3 search pages in an array and another that displays the includes randomly. The problem I am having is that I can't add the search phrase on to the array properly and instead end up with "search.php?query=$search_phrase;" instead of the right value for $search_phrase, which would be whatever the user puts in.


    PHP Code:
    <?php
        $expl 
    explode("/",$HTTP_SERVER_VARS["REQUEST_URI"]);
        
    $search_phrase $expl[count($expl)-1];
          print 
    $search_phrase;
    ?><br>

    $search_phrase;<br/>

    <?php
    $include_files 
    = array('search1.php?query=$search_phrase;','search2.php?query=$search_phrase;','search3.php?query=$search_phrase;',);
    shuffle($include_files);

    ?>

    <?php
     
    for ( $i 0$i 3$i++ )
     {
      include(
    $include_files[$i]);
     }
    ?>

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Anything in single quotes is treated as a literal, in short, you can't interpolate with single quotes, you'll have to use double quotes or concatenation:
    PHP Code:
    $include_files = array("search1.php?query=$search_phrase;","search2.php?query=$search_phrase;","search3.php?query=$search_phrase;",);

    $include_files = array('search1.php?query=' $search_phrase ';','search2.php?query=' $search_phrase ';','search3.php?query=' $search_phrase ';',); 

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    awesome

    thank you!

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    What you're doing won't work though. When you do an include, it isn't a HTTP request, so the $_GET superglobal isn't going to be populated.


  •  

    Posting Permissions

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