Pass an ID into new page.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Pass an ID into new page.

Post by synical21 »

Ive googled how to pass indentification into a new page and other various keywords and not finding much. The case isnt as simple as using $_SESSION as the id isnt the current users. On the page is a table, in this table is various user id's and a link to a new page in every row. The new page will be the process which interacts with the user id of that row.

User ID - Title - Link
User ID - Title - Link
User ID - Title - Link
User ID - Title - Link

isit possible?
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: Pass an ID into new page.

Post by AlanG »

Anything's possible if you wish hard enough. :)

Best method is to pass the id in as a get variable

(The Link has been replaced with the html code)

USER ID - Title - Link
1 - Tom - <a href="yourscript.php?id=1">Link</a>
2 - Tom - <a href="yourscript.php?id=2">Link</a>
3 - Tom - <a href="yourscript.php?id=3">Link</a>

In the yourscript.php you can catch the id using this code:

Code: Select all

$id = (isset($_GET['id']) && !empty($_GET['id']) && is_numeric($_GET['id'])) ? $_GET['id'] : 0;
If the id is set, not zero and is a number it will assign the number to $id, otherwise it will set it as zero. :)
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: Pass an ID into new page.

Post by synical21 »

Alan G to the rescue! :drunk:

I need to buy one of you from my local store :(

Havnt tested it yet but your replies always work
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Pass an ID into new page.

Post by requinix »

synical21 wrote:The case isnt as simple as using $_SESSION as the id isnt the current users.
As long as the current user doesn't change, you can put whatever you want in $_SESSION. Whatever. It doesn't have to be directly related to the current user.
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: Pass an ID into new page.

Post by AlanG »

synical21 wrote:Alan G to the rescue! :drunk:

I need to buy one of you from my local store :(

Havnt tested it yet but your replies always work
:) Not always... No one knows everything. :) Best of luck with it.
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: Pass an ID into new page.

Post by synical21 »

Just tested works like a charm thanks alan
Post Reply