Jump to content

Archived

This topic is now archived and is closed to further replies.

Morbid

Passing variables from a link?

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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Whew, wholesome goodness. Exactly what I was looking for. Thanks again.

Now, if only I had the parsing part done for all the specific stats. :P

Share this post


Link to post
Share on other sites

×

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.