Home     |     Photoshop    |     Flash General    |     Flash Actionscript    |     Dreamweaver    |     Macromedia Fireworks


Cervo Technologies
The Right Source to Outsource

Macromedia Dreamweaver

parsing variable/data from querystring


I am going to receive data in a querystring such as:

mypage.asp?id=325&prgm=2&datastr=var1^dat1^var2^dat2^var3^dat3

I need to break apart the datastr querystring value and send each var/dat
combo to a table along with the ID and prgm values, like:

ID    PRGM    VAR    DATA
------------------------------------
325    2            var1    dat1
325    2            var2    dat2
325    2            var3    dat3

Each case will have a different number of var/dat combos, and the "var"
names will also vary (they won't actually be var1, var2, etc.) - and I don't
know what they will be.  All I know is that whatever I get for "var" needs
to end up in the record in the VAR field, along with it's associated "dat"
in the DATA field.

How do I parse out those unknown number of var & dat values?

Thanks!

are you using PHP? coldfusion? ASP?

if PHP, try this (pseudo code):

$data = explode($_GET['datastring'],"^"); // or maybe its implode, I always
get them mixed up

$parsed_data

for(i=0;i<count($data);i=i+2){
  $d = $data[$i];
  $v = $data[$i+1];

  $parsed_data[$d]=$v;

}

// now the data is in a nice, usable array and you can create your SQL
queries to input the rows into the DB

// one last note, this seems like a weird way to pass data in a URL.  are
you trying to pass a whole array? IF you have the option, I would use
serialize & unserialize to do this instead. MUCH easier

--
Alex

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc