PHP $_GET Array

For discussion of the BB stats code.
nos

PHP $_GET Array

Post by nos » Sat Jan 12, 2008 10:54 pm

hey all,

Just wondering if anyone knows how to i can parse the pid array with php.
HTTP GET Query

Code: Select all

http://localhost/bf2142_stats/phpstats/stats2142.php?pid=101704187&pid=81279775&pid=90684521&pid=82890055


original ASP code

Code: Select all

if Request("pid") = "all" then
   redim pids(numnicks)
else
   pidst = Replace(Request("pid")," ","")
   pids = split(pidst,",")
end if


php code

Code: Select all

if($_GET["pid"] == "all")
{
   $pids = $nicks; /// I have altered this from the original code eg: nicks[$i]['pid'] //// nicks[$i]['nick']
}
else
{
echo $_GET['pid'];  //// echo the first pid in $_Get request
   //foreach($_GET['pid'] as $k => $v) /// loop through all pids in GET request
   //{
   //echo '<br />$k is equal to ' .$v;
   //}
}



so if i was to add [] to the name of each item in the array
php would read it fine.

Code: Select all

<input type="checkbox" name="pid[]" value=


but this cause's the java script used to CHECK all the input boxes to srew up and no longer works,
I tried to edit the JS but still didnt work.I'm guessing its not possible to pass a val with brackets in it
because it conflicts with JS.

is there any simple way to grab the vars from that query with the php $_GET function?

PS;
I'm not sure if u guys wont me to start a new topic each time I bring up a new subject of
questioning, If not just let me know what u would rather.

Cheers
Nos

User avatar
Piers
Comfortable with my sexuality
Comfortable with my sexuality
Posts: 1408
Joined: Fri Dec 02, 2005 7:57 am
Location: Horse country

Re: PHP $_GET Array

Post by Piers » Sun Jan 13, 2008 7:32 am

Multiple values for the same parameter in a GET request ought to automatically be converted into an comma-sep list of values for the value - don't test the query string directly.
That's why, even thought my querystring is pid=x&pid=y&pid=z... I simply do a split(pid,",") on the automatically created object.

I suggest you check the PHP manual or google - try http_get_request_headers, it returns a hash of keys & values.
Image

nos

Re: PHP $_GET Array

Post by nos » Sun Jan 13, 2008 9:36 am

Edit*****

Ok in the end i couldnt use http_get_request_headers, i had to grab the query string
and then just setup an array from the string.

Code: Select all

$pids = str_replace("&","",explode("pid=",$_SERVER['QUERY_STRING']));
echo $pids[4];


Cheers
Nos