Getting error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • youngpann42
    New Member
    • Oct 2012
    • 3

    Getting error

    Code:
    while($data_fetch=mysql_fetch_array($query_for_result))
    {
        echo "<li>";
        echo '<a href="<?php echo $user_data['username']; ?>">' .
    	substr($data_fetch[$db_tb_atr_name], 0,160). '</a>';
        echo "</li><hr/>";
    }
    but keeping getting this error

    Parse error: syntax error, unexpected 'username' (T_STRING), expecting ',' or ';' in D:\xampp\htdocs \Register\searc h.php on line 39

    can anyone help
    Last edited by zmbd; Oct 25 '12, 04:08 AM. Reason: Please format posted code using the <CODE/> button.
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    yes you should get this error. I will give you a simple tip to avoid this dumb error. just follow the statement below:

    Code:
    while($data_fetch=mysql_fetch_assoc($query_for_res ult)) //array create both string and integer indexing. which is not very useful but unnecessary
    {
    echo "<li>";
    echo '<a href="'.$user_data['username'].'">'.
    substr($data_fetch[$db_tb_atr_name], 0,160). '</a>';
    echo "</li><hr/>"; //I am not sure what you have wanted with this code but I have changed as i think it sould be. but still the output wont work properly cause your href will fail
    }
    now can you see and tell the difference?

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      You can use johny's method. But what you are trying to do can work if you use the correct syntax.

      1) Variables are only interpreted within strings if the string is demarcated with double quotes.

      2) When you want to interpret complex variables or constants in a string, you need to surround them in braces.

      Code:
      echo "{someArray['foo']}";

      Comment

      Working...