a href embedded in php not working

Discussion in 'PHP' started by daniah, Apr 13, 2007.

  1. #1
    Hi,
    Iam a beginner & still in the process of learning PHP. Iam not able to embed ahref with php mysql database commands.

    I used
    echo " <a href="$row['url']">$row['title']</a>"

    but it's showing an error.


    Pls help!

    Daniah
     
    daniah, Apr 13, 2007 IP
  2. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #2
    this will work


    echo " <a href=\"$row['url']\">$row['title']</a>";
     
    commandos, Apr 13, 2007 IP
    Clive likes this.
  3. daniah

    daniah Well-Known Member

    Messages:
    1,092
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    138
    #3
    Me still getting this error commandos
    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/lif/public_html/dir/xxx.php on line 43
     
    daniah, Apr 13, 2007 IP
  4. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    250
    #4
    Is line 43 the one that contains the code we're discussing here?
     
    Clive, Apr 13, 2007 IP
  5. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #5
    try this one :

     echo "<a href=\" $row[url] \">$row[title]</a>"; 
    Code (markup):
     
    commandos, Apr 13, 2007 IP
  6. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    250
    #6
    Or this one:
    
    echo '<a href="'.$row['url'].'">'.$row['title'].'</a>';
    PHP:
     
    Clive, Apr 13, 2007 IP
    commandos likes this.
  7. bouncer69

    bouncer69 Peon

    Messages:
    978
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Use Like

    <?php $url = $row["url"]; ?>
    
    <a href="http://<?=$url?>" target='_blank'><?=$row["title"]?></a>
    PHP:

    Also be sure that you call the right table from database before use this.
     
    bouncer69, Apr 15, 2007 IP
  8. Coltz-One

    Coltz-One Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This should also work

    echo " <a href=\'$row['url']\'>$row['title']</a>";
    PHP:
     
    Coltz-One, Apr 15, 2007 IP