PHP Echo Link

Discussion in 'Web Design and Development' started by SChaput, Feb 2, 2010.

  1. SChaput macrumors regular

    Joined:
    Jul 2, 2008
    Location:
    United States
    #1
    I'm trying to incorporate a link in a new element of my page. Here is my code:
    Code:
    echo "var marker = createMarker(point, '" .addslashes($row['city']) . ", " . addslashes($row['state_name']) . "<a href='http://www.ihatemyroommate.net/?id=$id'>View</a>" . "');\n";
    
    However, when loading the page up, nothing is displayed. If i remove the link aspect it all shows up fine, just with no link obviously. Am i using a wrong set of " or ' in my code?

    Thanks
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
  3. Denarius macrumors 6502a

    Denarius

    Joined:
    Feb 5, 2008
    Location:
    Gironde, France
    #3
    I've looked at your quotes three times and they look fine so I'd be looking upstream to your database query. Can't say for sure without seeing the error message though.

    Is this a private testing server? If it is, you might make your life easier by setting
    Code:
    display_errors = On
    in your php.ini file.
     
  4. stndn macrumors member

    Joined:
    Oct 22, 2006
    Location:
    earth
    #4
    This is what you'll get:
    Code:
    var marker = createMarker(point, '[b]cityname[/b], [b]statename[/b]<a href='http://www.ihatemyroommate.net/?id=[b]12345[/b]'>View</a>');
    (Note: example output from your variables are bolded)

    Is that what you wanted?
    Because we can see the single quote was started before the cityname, and ended after </a>. So the opening <a> tag was inside single quote.

    And even if that's true, the single quote before http would cancel the single quote at the start of 'point' anyway


    -stndn.
     
  5. Denarius macrumors 6502a

    Denarius

    Joined:
    Feb 5, 2008
    Location:
    Gironde, France
    #5
    Wow, I hadn't even thought about the validity of the javascript.
    If this is for google maps, this page might help you. Seems to be that point should be latitude and longitude and the second argument should only be the anchortag, which kind of makes the $row['city']and &row['state'] and thus PHP in that line redundant anyway.
     
  6. Cerebrus' Maw macrumors 6502

    Joined:
    Mar 9, 2008
    Location:
    Brisbane, Australia
    #6
    On a Mac, if you are using Firefox, press

    Cmd +Shift + J

    and this will bring up the Error Console and click the tab for Errors (make sure you clear it, as it will have errors from every site you visited) then reload your page and check the Errors, it should show any Javascript errors that are being reported.

    I believe there is also a Console on Safari, but not on OS X at the moment...
     

Share This Page