Accessing variable value by _GET

I stored one variable name “campname1” with value “Hosting Campaign”. Now when I press submit button then I wish to access this value but not with simple $_GET[‘campname1’]. Here is scenario.

“campname” is constant and 1 added at the end is increasing according to number of rows in table. For example.
$sno = 1;
$varname = “campname”.$sno;
Now $varname has value “campname1” and I wish to access “campname1” data by $_GET command

What’s the exact command?

$varvalue = $_GET[$varname] or
$varvalue = $_GET[$$varname]

How to retrieve this variable data?

Use an array for the form field, with either specific integer indexes campname[1], campname[2], …or just leave the index empty campname[], campname[], …and let them be automatically assigned values (starts at zero.)

You will then SIMPLY loop over the submitted data using a foreach(){} loop -

foreach($_GET[campname] as $key=>$value)
{...}

When you have sequential values it is a big red flag of a design problem. Rather than ask about your attempted solution, tell us about the real problem you are trying to solve.

Sponsor our Newsletter | Privacy Policy | Terms of Service