Jump to content


Photo

Passing variables from a link?


  • Please log in to reply
4 replies to this topic

#1 Morbid

Morbid
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 April 2006 - 03:40 AM

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 search for I'd really appreciate it.

Thanks.


#2 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 05 April 2006 - 03:54 AM

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:

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

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:

$_GET['key']

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:

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

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:

link.php?var1=stuff&var2=stuff

hope this helps.

#3 Morbid

Morbid
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 April 2006 - 04:02 AM

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.

#4 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 05 April 2006 - 04:04 AM

glad to help.

#5 Morbid

Morbid
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 April 2006 - 04:19 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users