form with 2-dimensional array

A

Anonymous

Guest
I have a form with textfields for 20 usernames and for each of them 10 checkboxes defining their rights. So I want to have a 2-dimensional array. The first dimension is the username with his rights and the second dimension are the 20 users.

I thought I could name the fields:

name="user[1]['name']"....name="user[20]['name']"

and the checkboxes f.e.

name="user[1]['edit']"...name="user[20]['edit']"

I can't echo them this way. How should I write this code or has anybody a better idea for handling this?

Thanks

miss_marple
 
Code:
<input type="text" name="names[]" />
   <input type="checkbox" name="names1[]" />
   <input type="checkbox" name="names1[]" />
   <input type="checkbox" name="names1[]" />
   <input type="checkbox" name="names1[]" />
   <input type="checkbox" name="names1[]" />
...
...
<input type="text" name="names[]" />
   <input type="checkbox" name="names2[]" />
   <input type="checkbox" name="names2[]" />
   <input type="checkbox" name="names2[]" />
   <input type="checkbox" name="names2[]" />
   <input type="checkbox" name="names2[]" />
...
...
<input type="text" name="names[]" />
<input type="text" name="names[]" />
...
...
 
Can't the textfield be the first element in the user's array ?
like
Code:
user[1]['name']
 
Miss_Marple said:
I can't echo them this way. How should I write this code or has anybody a better idea for handling this?

Why not? A foreach ought to work fine.
 
if the value of

Code:
user[1]['name']

should be 'myname', and I want to echo this single value like

Code:
echo $user[1]['name'];

all I get is:

myname['name']
 
I don't know what you are using....
but just to check what you want... and how you can print the values...

try the below code
Code:
echo "<pre>";
print_r($_POST);

print_r($_GET);
echo "</pre>";
 
Back
Top