If statement problem :(

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Publisher Bucks
    Confirmed User
    • Oct 2018
    • 1330

    #1

    Tech If statement problem :(

    <?php if($website) { ?><a href="http://<?php echo $website; ?>" target="<?php echo $name; ?>"><?php echo $name; ?></a><?php } ?>
    Any idea why this is removing the $name field completely in addition to the link?

    All Im trying to get it to do is still display the name, just remove the href link if no website is included in the DB
    Extreme Link List - v1.0
  • redwhiteandblue
    Bollocks
    • Jun 2007
    • 2793

    #2
    Because if the condition in the if statement is false, none of the code inside the curly braces will execute.
    Interserver unmanaged AMD Ryzen servers from $73.00

    Comment

    • Publisher Bucks
      Confirmed User
      • Oct 2018
      • 1330

      #3
      Originally posted by redwhiteandblue
      Because if the condition in the if statement is false, none of the code inside the curly braces will execute.
      Gotcha, thank you!
      Extreme Link List - v1.0

      Comment

      • redwhiteandblue
        Bollocks
        • Jun 2007
        • 2793

        #4
        BTW, rather than writing
        Code:
        <?php echo $website; ?>
        you can shorten this to
        Code:
        <?=$website;?>
        Interserver unmanaged AMD Ryzen servers from $73.00

        Comment

        • Publisher Bucks
          Confirmed User
          • Oct 2018
          • 1330

          #5
          Originally posted by redwhiteandblue
          BTW, rather than writing
          Code:
          <?php echo $website; ?>
          you can shorten this to
          Code:
          <?=$website;?>
          Good to know!

          I was actually going to post in a few weeks to see where I could shorten some of the code I'm using on my admin system and I'm sure its over-inflated, but I need to get things finished up with it first.
          Extreme Link List - v1.0

          Comment

          • sarettah
            see you later, I'm gone
            • Oct 2002
            • 14297

            #6
            Be careful using short codes. They require an ini setting that is not always turned on. So code that works on one server may not work on another.

            It can also lead to some issues when dealing with xml which also uses an <? ?> Syntax.

            .
            All cookies cleared!

            Comment

            • redwhiteandblue
              Bollocks
              • Jun 2007
              • 2793

              #7
              Originally posted by sarettah
              Be careful using short codes. They require an ini setting that is not always turned on. So code that works on one server may not work on another.

              It can also lead to some issues when dealing with xml which also uses an <? ?> Syntax.

              .
              You're talking about short open tags - <? ... ?> which are possibly being deprecated.

              The short echo tags <?= ... ?> are not dependent on an ini setting https://www.php.net/manual/en/langua...ax.phptags.php and there's no proposal to deprecate them.
              They are actually line 1 of the PSR-1 coding standard https://www.php-fig.org/psr/psr-1/

              Not that anyone actually follows that...
              Interserver unmanaged AMD Ryzen servers from $73.00

              Comment

              • sarettah
                see you later, I'm gone
                • Oct 2002
                • 14297

                #8
                Originally posted by redwhiteandblue
                You're talking about short open tags - <? ... ?> which are possibly being deprecated.

                The short echo tags <?= ... ?> are not dependent on an ini setting https://www.php.net/manual/en/langua...ax.phptags.php and there's no proposal to deprecate them.
                They are actually line 1 of the PSR-1 coding standard https://www.php-fig.org/psr/psr-1/

                Not that anyone actually follows that...



                Interdasting. I learn something new about every 2 minutes.

                Thanks for that.

                .
                All cookies cleared!

                Comment

                Working...