Jump to content

Passing variables from a link?


Morbid

Recommended Posts

Hello everybody. This isn't so much of a "How do I?" question, more of a "What's it called?"

In an attempt to begin learning PHP I undertook the development of a stats processor for W:ET. I realize there are many out there, but I needed something I could use in order to challenge myself. I'm using Python to parse the server log and populate my MySQL database.

I'm attempting to use PHP to access the info from the database and display it.

(Think that's enough useless background for now...)

Anyway, let's say my first page consists of all the players and general stats, like kills and deaths. What I want is each player name to be hyperlinked so you could view specific stats for that particular player. So I'll have a playerProfile.php page that access all valid info for specified player, and display it, all it needs to know is which player to grab all valid data for. So each player link should link to playerProfile.php, and say "I'm player <player>"

I'd really just like to know what this process is referred to so I know what to search for. Where I stand right now...well, I'm clueless. :P

So if anybody could just give me some things to [b]search[/b] for I'd really appreciate it.

Thanks.
Link to comment
Share on other sites

wow - for once someone who is willing to learn, not just copy and paste. this is refreshing.

anyhow, what you're looking for are URL variables, formally known as sending a GET request. when you construct a link like so:

[code]<a href="link.php?key=value">Link</a>[/code]

then on the receiving page, a GET request has been sent with the info specified in the URL. this information is stored in the superglobal (just meaning accessible anywhere in a script) $_GET, which for all intents and purposes acts exactly like a regular array. in this case, the value "value" is accessible in:

[code]$_GET['key'][/code]

it sounds like what you are looking for is simply a link that sends the player's ID. i reckon echoing a link like so in your table (or however you're displaying the players) will work:

[code]<a href="playerProfile.php?player_id=$idhere">Player Name</a>[/code]

then on playerProfile.php, your player's ID is stored in $_GET['player_id'] and can be used accordingly in a query to grab his stats.

any number of variables can be appended to the request and sent to the $_GET array by using & between variables, like so:

[code]link.php?var1=stuff&var2=stuff[/code]

hope this helps.
Link to comment
Share on other sites

Thanks a lot man, should be plenty to help me get started. I'll play around with what you've listed and see what happens. :P

It's frustrating not knowing what to look for when you wanna do something.

Again, thanks a lot.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.