Arrays of Arrays !!

Codes here !

Moderators: macek, egami, gesf

AimSkyward
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Jul 22, 2013 10:42 am

Arrays of Arrays !!

Postby AimSkyward » Sun Aug 04, 2013 7:58 am

Hi all,

I am looking to do something rather straightforward but being new to PHP I'm getting a bit stuck.

I have an html form with radiobuttons that are linked in pairs (input or output). I have linked them (same 'name') so that pressing one effects the other i.e it can only ever be either an input or output never both. These are set up as arrays of two members (input & output)

Code: Select all

<input type="radio" name="rad1"value="CH1_IN">
<input type="radio"name="rad1"value="CH1_OUT">

I have a .php script that takes these posted arrays

Code: Select all

$DigIO=$_POST['rad1'];

and goes through a 'for' loop to get both items of the array out and then inserts them into a MySQL table.
The problem I am trying to solve is how I can create an array of these radio-button arrays to prevent having to repeat the same code time and time again (I have 16 pairs of buttons!!).
I have tried doing what I thought might work

Code: Select all

$DigArray = array("rad1", "rad2", "rad3".............."rad16")
for($j=0;$j<16;$j++)
{$DigIO = $_POST['$DigArray[$j]']
and then going into a second 'for' loop to get both input and output readings before inserting them into the table but not surprisingly it didn't work.
I would be grateful for any ideas.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Arrays of Arrays !!

Postby johnj » Tue Aug 06, 2013 11:28 pm

$_POST is an array. So, print this array to see how you are receiving form variables.
do a print_r($_POST)

AimSkyward
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Jul 22, 2013 10:42 am

Re: Arrays of Arrays !!

Postby AimSkyward » Sat Aug 10, 2013 2:25 am

Thanks johnj, I will give that a go and see if it gives me a better idea of what's going on.

Cheers


Return to “mySQL & php coding”

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron