another PHP/MySQL question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poe
    Confirmed User
    • Mar 2004
    • 455

    #1

    another PHP/MySQL question

    I am creating links for mysql data..

    my code looks like this

    Code:
    echo "<a href=".$row['url']." title=".$row['title'].">".$row['name']."</a>";
    now, sometimes there is no 'url' data for that entry.. how do make it so if there isn't, it doesn't display that entry as a link?

    thanks!
  • poe
    Confirmed User
    • Mar 2004
    • 455

    #2
    the name should still be displayed, just not the link

    Comment

    • Voodoo
      ♥ ♦ ♣ ♠
      • Sep 2002
      • 10600

      #3


      Read a book.

      "I'm selflessly supporting the common good, but only coincidentally looking out for No.1."

      Comment

      • poe
        Confirmed User
        • Mar 2004
        • 455

        #4
        Originally posted by Voodoo


        Read a book.

        Comment

        • Voodoo
          ♥ ♦ ♣ ♠
          • Sep 2002
          • 10600

          #5
          Code:
          if(isset($row['url'])){
          echo "<a href=".$row['url']." title=".$row['title'].">".$row['name']."</a>";
          }else{
          echo "$row['name']";
          }
          Try this.

          "I'm selflessly supporting the common good, but only coincidentally looking out for No.1."

          Comment

          • poe
            Confirmed User
            • Mar 2004
            • 455

            #6
            Thanks, dude!

            hmm, it doesn't produce any errors, but it doesn't work.. should i try something other than isset?

            Comment

            • poe
              Confirmed User
              • Mar 2004
              • 455

              #7
              switched around the if and else and tried empty()

              that worked!

              thanks!

              Comment

              • poe
                Confirmed User
                • Mar 2004
                • 455

                #8
                also: i have a separator between each entry.. is there an if something() to check if it's the last entry, so the separator doesn't show up at the end?

                Comment

                • poe
                  Confirmed User
                  • Mar 2004
                  • 455

                  #9
                  it's now 1041

                  Comment

                  • Voodoo
                    ♥ ♦ ♣ ♠
                    • Sep 2002
                    • 10600

                    #10
                    Code:
                    if($row['url'] != empty){
                    echo "<a href=".$row['url']." title=".$row['title'].">".$row['name']."</a>";
                    }else{
                    echo "$row['name']";
                    }

                    "I'm selflessly supporting the common good, but only coincidentally looking out for No.1."

                    Comment

                    Working...