zero-perfoliate
zero-perfoliate

Author Topic: 3D Array's from a form  (Read 231 times)

Offline TomSayer

  • PHP Workers
  • **
  • Posts: 14
  • Karma: +0/-0
3D Array's from a form
« on: March 08, 2010, 05:46:24 AM »
I've had  quick search through the forums, and couldn't find anything related to this!
What i'm trying to do is take 3D array data from a form of variable length (depending upon how many dba entries are called).
The form is to allow me to quickly edit around 40 odd users with varying pieces of data for each.
When the form is generated, each user has 5 pieces check boxes associated to it in the array, as below.
Code: [Select]
<input type='checkbox' name='pass[29][mon]' value='1'>the first [] being the individual user, the second the relevant data.
The form is being generated as it should be, however when its posted to be processed, none of the information is being recieved. It could be that i'm trying to call it wrong ($_POST['pass[$i][mon]'], $i being the users ID generated whilst looping through)? I've not had to deal with 3d arrays before, or arrays from forms, so i could be doing this entirely wrong!

Hopefully i've been clear enough in this! If not, ask for more!

~Tom

hotnoob

  • Guest
Re: 3D Array's from a form
« Reply #1 on: March 10, 2010, 11:21:07 AM »
if you are going to put a variable in a name it should be with " " instead of ' '
Single quotes are for static strings
double quotes are for dynamic strings.

So to solve your problem... if you are using a loop of some sort... i can only assume...
Code: [Select]
<?php
  
//ill make a loop if u havnt anyway...
  //you can use isset if you want, but i like empty() better
  
$i 0// set it to 1, if u started with 1.
  
while(!empty($_POST['pass['.$i.'][mon]']))
  {
     echo 
$_POST['pass['.$i.'][mon]'];
     
//or
     
echo $_POST["pass[$i][mon]"];
     
$i++;
  ]
?>



i also don't like for loops :P

Offline TomSayer

  • PHP Workers
  • **
  • Posts: 14
  • Karma: +0/-0
Re: 3D Array's from a form
« Reply #2 on: March 10, 2010, 11:33:32 AM »
I hate them too :P Nothing wrong with while!
& thanks for the help, i had a good google looking for references, but never found it!

I'll plug that in and see how we're doing after the football!

 

zero-perfoliate