How do i echo this?

Discussion in 'PHP' started by sittsait, Sep 16, 2008.

  1. #1
    I have syntax errors in this piece of code. Cant get it right in echo :confused:
    You can :)?

    
    echo "</tr><tr>
                               <td class='photo'><a href="'.getNormalImage($file).'" onclick='NewWindow(this.href,'name','240','500','yes');return false'>
                                   <img src="'.$file.'" width='134' height='114' onContextMenu='return false;' border='0'/></a></td>";    
    Code (markup):
     
    sittsait, Sep 16, 2008 IP
  2. Dollar

    Dollar Active Member

    Messages:
    2,598
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    90
    #2
    You forgot to escape the Quotes. Since the echo is already in Quotes you need to make sure to add slashes to the quotes in html that is being echoed or else it will think the echo ended and throw an error

    For example if you put

    You need add slashes the the qoutes in the src like

    
    echo "</tr><tr><td class='photo'><a href=\"'.getNormalImage($file).'\" onclick='NewWindow(this.href,'name','240','500','yes');return false'>
                                   <img src=\"'.$file.'\" width='134' height='114' onContextMenu='return false;' border='0'/></a></td>";
    PHP:
     
    Dollar, Sep 16, 2008 IP
  3. Hade

    Hade Active Member

    Messages:
    701
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    90
    #3



    Almost right. It should actually be:

    echo "</tr><tr><td class='photo'><a href=\"".getNormalImage($file)."\" onclick='NewWindow(this.href,'name','240','500','yes');return false'>
                                   <img src=\"".$file."\" width='134' height='114' onContextMenu='return false;' border='0'/></a></td>";
    PHP:
     
    Hade, Sep 16, 2008 IP
  4. nabz245

    nabz245 Well-Known Member

    Messages:
    677
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Anytime you use a quote inside a quote (like above) you need to add a \ before the inner quote.

    echo "this is just a \"example\"";

    The about would output: this is just a "example"

    I hope that helps clear things up!

    Regards
     
    nabz245, Sep 16, 2008 IP
  5. sittsait

    sittsait Guest

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks guys.
    Your codes fixed the errors but didnt open a popup :p
    The finalized version comes here:

    
    echo "</tr><tr>
    <td class='photo'><a href=\"".getNormalImage($file)."\" onclick=\"NewWindow(this.href,'name','800','000','yes');return false\">
                                   <img src=\"".$file."\" width='134' height='114' border='0'/></a></td>";    
    
    Code (markup):
    Ty so much.
     
    sittsait, Sep 16, 2008 IP
  6. ricetown

    ricetown Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This is the best answer for the question.:)
     
    ricetown, Sep 16, 2008 IP
  7. nabz245

    nabz245 Well-Known Member

    Messages:
    677
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #7
    If the popup didn't appear, theres probably a error in your javascript code.
    Have you tested the popup <a href in plain html? Does it work then?
     
    nabz245, Sep 16, 2008 IP