A HREF Promlems

Discussion in 'PHP' started by aaron_nimocks, Dec 26, 2006.

  1. #1
    Im going to hit myself for sure once I figure this out but I have been having trouble trying to return a URL from a database and displaying a link using that info. Heres what I have

    ?><div><? echo $row['url']; ?></div><?
    PHP:
    Now of I want it to be a link with the anchor text the same url value. Can someone help me please! :)

    Would be something like this I am guessing, but this dont work.

    ?><div><? echo "<a href'.$row['url'].'>.$row['url'].</a>; ?></div><?
    PHP:
     
    aaron_nimocks, Dec 26, 2006 IP
  2. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Something like:

    ?><div><? echo "<a href='" . $row['url'] . "'>" . $row['url'] . "</a>"; ?></div><?

    you mean?
     
    TwistMyArm, Dec 26, 2006 IP
    aaron_nimocks likes this.
  3. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #3
    Ya that works.

    Thanks! :)
     
    aaron_nimocks, Dec 26, 2006 IP
  4. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Let's also teach some best practices. :p
    (Hint: Look at the quotes. ;))

    echo '<a href="'. $row['url'] .'">'. $row['url'] .'</a>';
    PHP:
     
    Icheb, Dec 26, 2006 IP
  5. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I agree that 'best practices' are good to be taught (I thought about requoting that string) but then figured:
    a) sometimes it's better to make the least changes possible (easier to diff); and
    b) (no offence to you, aaron_nimocks, but) the guy had PHP / HTML code that included not setting an HREF correctly (no equal sign), a single, unclosed string and concatenations inside of that string.

    Sometimes it's best to just do what you have to do.
     
    TwistMyArm, Dec 27, 2006 IP