We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24161
    • 16 Posts
    I’m a complete NOOB with PHP. I’m used to more ’common english’ web languages like ColdFusion or ASP. And in those, I’d know how to do the following, but in PHP it’s seemingly impossible:

    For my navigation, I need to check the URL variable ID, and depending on what it is, export out some HTML/JAVASCRIPT for the page to parse. In ColdFusion, this’d be a cinch, and would go like this:

    <cfif Request.ID IS "47">
        <html code>
    <cfelse>
        <other html code>
    </cfif>
    


    But in PHP, I’m not sure what to do. I’ve tried using an echo(’’), but that just results in a broken page. Can anyone help? I’m assuming this is simple, cause it’s so easy in other languages, but exhaustive web searching has yielded nothing.
      • 33372
      • 1,611 Posts
      This seems like a general PHP question, but I wonder if you’ve investigated the many ways to vary content using MODx yet...

      The PHP syntax for what you’re doing is:
      if($_REQUEST['yourvar']=='47'){
          echo'<html code>';
      }
      else{
          echo'<other html code>';
      }


      or

      <?php
      if($_REQUEST['yourvar']=='47'){
      ?>
      <html code>
      <?php
      }
      else{
      ?>
      <other html code>
      <?php
      }
      ?>


      You’ll find all the info you need on PHP (and more) at www.php.net.
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
        • 24161
        • 16 Posts
        Nope. Doesn’t work, I’ve already tried a few iterations of the same concept - it puts both options there, rather than just one or the other.
          • 30223
          • 1,010 Posts
          Most likely reason is that your php isn’t parsed. My guess is that you’re placing the php code in the document? Assuming you’re doing this in MODx you need to place the above code in a snippet and then call the snippet in your document. Read all about snippets in the documentation

          Oh, by the way ZAP it’s $_REQUEST, not $REQUEST
            • 33372
            • 1,611 Posts
            Quote from: TobyL at Feb 09, 2007, 02:55 AM

            Oh, by the way ZAP it’s $_REQUEST, not $REQUEST
            Oops! Copy and paste can be your best friend or your worst enemy. Depends on what you copy...
              "Things are not what they appear to be; nor are they otherwise." - Buddha

              "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

              Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options