Getting a parser error while echoing this html

Discussion in 'PHP' started by inhook, Mar 28, 2009.

  1. #1
    can somebody look at this and let me know what should be the appropriate syntax for the following code.

    This is what i want to echo to the browser

    <li><a href="#" onClick="makeRequest('2105', 'itemDisplay');">itemname</a></li>
    PHP:

    this is what the script is echoing:

    echo "<li><a href=\"#\" onClick=\"makeRequest("'" .$info1['cat_id']. "'",'itemDisplay');\">"'" .$info1['cat_name'] . "'"</a></li>" ;
    PHP:
    the php echo is giving me a parser error. i have tried other things where it displays without the parser error but i am not able to figure out how to how to echo the single quotes also after the makerequest in the functions.

    Your help will be appreciated.
     
    inhook, Mar 28, 2009 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    
    $cat_id = $info1['cat_id'];
    $cat_name = $info1['cat_name'];
    echo "<li><a href=\"#\" onClick=\"makeRequest('$cat_id','itemDisplay');\"> $cat_name</a></li>" ;
    
    Code (markup):
    try that
     
    shallowink, Mar 28, 2009 IP
  3. inhook

    inhook Well-Known Member

    Messages:
    248
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #3
    works like a charm thank you very much
     
    inhook, Mar 28, 2009 IP
  4. steelaz

    steelaz Peon

    Messages:
    47
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    echo "<li><a href=\"#\" onClick=\"makeRequest('{$info1['cat_id']}','itemDisplay');\">{$info1['cat_name']}</a></li>" ;
    PHP:
     
    steelaz, Mar 28, 2009 IP