www.webdeveloper.com
Results 1 to 7 of 7

Thread: variables in php

  1. #1
    Join Date
    Nov 2012
    Posts
    3

    variables in php

    Hey all I have the following set up

    <?php
    if ($type[$r]=="finding happiness") {$vidlink="http://www.mormonchannel.org/mormonmessages?v=910937379001";}
    else {$vidlink="http://www.lds.org";}
    ?>


    later, in other php page, i have this..

    <a id='findmore' href="<?php echo $vidlink ?>" target='_blank'><h3>Find out more about <?php echo $type[$r] ?>.</h3></a>


    even when i know the value of $type[$r] IS "finding happiness" it always goes to lds.org. No syntax errors seem to be cropping up so what am I missing? Thanks.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,432
    Quote Originally Posted by ThatJimGuy View Post
    ...
    later, in other php page, i have this..
    ...
    Unless that "other php page" is included/required by the original script (or vice versa), then the 2nd script has no knowledge of any variable assignments in the first. If that's the issue, then you may want to look at using session variables. If that's not the issue, then you may need to do more debugging to verify what values are being set and if/when they are getting overridden.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2012
    Posts
    3
    Yes, it is included before the link hits. any other ideas?

    Thanks for responding

  4. #4
    Join Date
    Aug 2006
    Posts
    1,922
    You might do a print_r on $r, $type[$r] and $vidlink, just after setting in the first block, and just before the anchor in the second block, to make sure they're all as expected. Somewhere, they're not.

    Dave

  5. #5
    Join Date
    Nov 2012
    Posts
    3
    I did that too, but good call. It reads that it goes straight to the lds website and ignores the positive
    statement/

  6. #6
    Join Date
    Aug 2006
    Posts
    1,922
    Could you show us that code and output please... hard to guess what's wrong without seeing it.

    Dave

  7. #7
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,432
    maybe trim() the value being checked in the if() statement, in case there are any white-space characters at either end?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles