Tech Off Thread

7 posts

Passing php variables via "a name" links - Help?

Back to Forum: Tech Off
  • User profile image
    Cybermagell​an

    I'm trying to write a website that is dependant on being able to make a name links...so....

    <a href="foo.html">foo</a>
    <a href="#bar">bar</a>

    <div name="bar">
    </div>

    However I want the content inside the bar div to give php variable information....thus...

    I wanted to try to form my link as such...

    <a href="#bar?var=value">bar</a>

    However it isn't working....any ideas?

  • User profile image
    JChung2006

    Cybermagellan wrote:

    I wanted to try to form my link as such...

    <a href="#bar?var=value">bar</a>

    However it isn't working....any ideas?

    Try:

    <a href="?var=value#bar">bar</a>

  • User profile image
    evildictait​or

    Browsers dont go back to the server when you give them an internal ("#") link. Even when you think adding get-parameters would work, it often doesn't due to caching, so you can either

    a) Add random data to the end of the link:\
     <a href="mypage.php?important=data&random=ahadhqw#internallink">link</a>
    b) Use javascript nastyness:
    <a href="mypage.php#bob" onclick="getdata('mypage.php')">link</a>

    If your php page returns a constant result (up to arguments) then the caching problem goes away, and you can just use ?get=args#internallink. Note that the ? must come before the #.

  • User profile image
    RichardRudek

    Cybermagellan wrote:
    <a href="#bar?var=value">bar</a>


    I've never actually used PHP before, so obviously, take this with a (huge) 3 carrot grain of salt, but it looks like your trying to get PHP to work within a string constant.

    I'd have thought it would have been better to have PHP return the entire (computed) string instead. Just a thought.

    EDIT:

    Oh stupid me. You mean from the client, passing data back to your server using URL variables.

    In other words, that fact that the server is using PHP isn't significant. I was looking at it from the Server side, and thinking you were using some kind of wierd PHP shortcut syntax that I'd never seen before... move along, nothing to see here...

  • User profile image
    Cybermagell​an

    Actually this was for an iPhone web app....and that wasn't working...as it turned out I'm just going to use PHP vars and create the page as needed.

  • User profile image
    W3bbo

    Cybermagellan wrote:
    Actually this was for an iPhone web app....and that wasn't working...as it turned out I'm just going to use PHP vars and create the page as needed.


    Just use $_SESSION

  • User profile image
    wisemx

    I'd rather be mauled by mosquitoes that write PHP....
    ...but it is interesting that Microsoft has taken the reigns. Big Smile

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.