Jump to content

Querystring loop... Simple but not getting it.


kaustic

Recommended Posts

I have an SWF passing a querystring to a PHP file.

 

ex: page.php?var=foo&var=bar&var1=3

 

The querystring contains multiple values with the same key (var in the example above).

 

How can I loop through the "var" key and get its values? I've tried over and over again with no luck. Basically, using the example above, I'd like to loop through var and echo all values (foo and bar).

 

I realize this is probably simple but I'm simply not able to get a loop to work with the querystring. Any help would be appreciated.

Patrick, that worked. I added an if statement to pull just the var values. Is there a more efficient manner if all I want to extract is the var values?

 

Thanks for the help. I'd tried something similar but never got it to work. Think I've been up too long.

Why are you getting data like this: page.php?var=foo&var=bar&var1=3 instead of like this: page.php?var[]=foo&var[]=bar&var1=3 ?  The latter affords you the ability to access var through the $_GET array as an array ala:

 

<?php
print_r($_GET);
// prints: Array ( [var] => Array ( [0] => foo [1] => bar ) [var1] => 3 )
?>

 

Best,

 

Patrick

I see.  Unfortunately there's not going to be a really elegant solution to the problem, since you're dealing with data that is technically malformed.  Parsing the query string manually (like the code I originally posted) is probably your best bet.

 

Patrick

Archived

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

×
×
  • 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.