Jump to content
MakeWebGames

Variable inside $_GET


Recommended Posts

Posted

I'm trying to write a little snippet of code, and I've encountered a problem. What I'm trying to do, is to put a variable with a value inside the $_GET, e.g:

 

$b = 1;
$c = $_GET['data{$b}'];

 

And later I use a while loop to auto increment $b + 1 for so and so many times. My problem is, I can't get this to work! It simply doesn't read the variable, no matter what I try. Does anyone have any suggestions on how to fix this? Thank you very much.

Posted

what i think he is trying to do is this

$b = array('1a', '2b', '3c', '4d', '5e'); //put the data into an array
$c = $_GET['data-'.implode(',', $b)]; // make the array a string and add "data-" before it

//then to get the info
$data=explode('-', $c); //makes $c into an array with data as $c[0] and your data string as $c[1] (to add more data just add "-" then your string) 
$data=explode(',', $data[1]); // remakes the origanal array from the string

echo $data[0]; //returns 1a

this is not tested but hope it helps :)

Posted

lol i just saw what i wrote lack of sleep and a 14 hour shift does hell for my coding :P

it should be

$b = array('1a', '2b', '3c', '4d', '5e'); //put the data into an array

$_GET['data]=implode(',', $b); // make the array a string and assign it ot $_GET['data']

$c=$_GET['data'];

//then to get the info

$data=explode('-', $c); //makes $c into an array with data as $c[0] and your data string as $c[1] (to add more data just add "-" then your string)

$data=explode(',', $data[1]); // remakes the origanal array from the string

echo $data[0]; //returns 1a

Posted
lol i just saw what i wrote lack of sleep and a 14 hour shift does hell for my coding :P

it should be

$b = array('1a', '2b', '3c', '4d', '5e'); //put the data into an array

$_GET['data]=implode(',', $b); // make the array a string and assign it ot $_GET['data']

$c=$_GET['data'];

//then to get the info

$data=explode('-', $c); //makes $c into an array with data as $c[0] and your data string as $c[1] (to add more data just add "-" then your string)

$data=explode(',', $data[1]); // remakes the origanal array from the string

echo $data[0]; //returns 1a

lol I'm also wondering how you got this problem to solve from looking at his topic... Nothing is said about arrays, 1a 2b etc., or the format of his data... :P
Posted

I don't think so...

You have the added processing/time penalty of having to implode/explode variables, compared to using GET variables normally.

Still, when faced with this situation it would be better to not use GET variables at all...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...