Forum Moderators: open

Message Too Old, No Replies

Creating a hyperlink that pulls page ID

Creating a hyperlink that pulls page ID

         

ghostman 0007

5:14 pm on Feb 21, 2008 (gmt 0)

10+ Year Member



I have a page that pulls some SQL data results using the id from the url:

test.php?id=20

I need to create a hyperlink that uses the id from the url to open a survey that corresponds to that id.

Any assistance would be GREATLY appreciated.

Thanks Much!

eelixduppy

5:33 pm on Feb 21, 2008 (gmt 0)



Something like this?

<a href="test.php?id=20">Click me</a>

btw, Welcome to WebmasterWorld! :)

ghostman 0007

7:15 pm on Feb 21, 2008 (gmt 0)

10+ Year Member



Thanks for the reply and the welcome eelixduppy.

I know how to link directly using the id as you showed in the example, however, I would like to have it were the hyperlink pulls the id from the url dynamically so I don't have to code all the pages with the id# in the link manually.

Any ideas would be appreciated...

Thanks Much!

eelixduppy

7:19 pm on Feb 21, 2008 (gmt 0)



This would go into the code where you retrieve the data from the database table. Since you are using PHP you might want to go over to the PHP Forum for additional help with this and post the relevant php code that gets the data.

ghostman 0007

8:04 pm on Feb 21, 2008 (gmt 0)

10+ Year Member



What I am wanting to do is have a link that will pull the page ID and add it to the link so when it opens it opens the same page ID. I may be going about this the wrong way so here is what I am doing:

I have a page that when loaded it loads with a page id so some SQL info can be loaded. There is a survey that is page id specific that submits the results to the database that the page originally pulls. So for example, test.php?id=20 will pull the results for the SQL info for that input - I want a dynamic link on that page that when I click it it will open the survey with the following:

survey.php?id=20

I can hard code the link to bring the specific survey but I will have several different pages that I would like to page id and allow the hyperlink to pull the survey page id.

Hope that makes a little more sense. If there's a different way of doing this or another forum to post I will gladly do so, and I appreciate the assistance thus far.

fside

2:14 am on Feb 22, 2008 (gmt 0)

10+ Year Member



One can only guess what you mean if you don't post your code. But you suggest that you are viewing a page with search arguments in the URL. You are viewing page - http://example.com/test.php?id=20. So you do not hardcode the page with a unique id. But you believe that it can be uniquely identified by passing the id in the arguments of the page's URL? If so, you have the id which to 'pull'.

You want to create a link, which doesn't exist on the page - ./survey.php?id=20. So you createElement("a"), and the href attribute would be "./survey.php?id" +top.location.search.substring(1).split("="). Then you pick the element where you want it to appear, and append.

var placeHere = "heregoes";
var elmt = document.createElement("a");
elmt.href = "./survey.php?id=" +top.location.search.substring(1).split("=")[1];
elmt.innerHTML = "click here";
document.getElementById(placeHere).appendChild(elmt);

[1][edited by: tedster at 2:41 am (utc) on Feb. 22, 2008]
[edit reason] switch to example.com - it can never be owned [/edit]