Re: Nested foreach ?
| From: | John Holmes | Date: | Sun, 17 Oct 2004 21:55:10 +0000 |
| Subject: | Re: Nested foreach ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-199683@lists.php.net to get a copy of this message | ||
Stuart Felenstein wrote:
John, Sorry, I'm not trying to be unclear. There are 3 columns in the table. In the user form. there are 30 fields, 10 text and 20 dropdown. The 10 text are: $_SESSION['skills'] = $_POST['skill']; The first dropdown is : $_SESSION['skys'] = $_POST['sky']; The second dropdown is: $_SESSION['slus'] = $_POST['slu']; So I need to grab the input and enter into database where each set of skill, sky , slu is a new record. I hope this is clearer.Did you read the answer I gave?
Now adapt that to your session variables and query: foreach($_SESSION['skills'] as $key => $skill) { $query = "INSERT INTO table (skill, sky, sku) VALUES ('$skill', {$_SESSION['skys'][$key]},{$_SESSION['slus'][$key]})"; //run query } or, if you can use extended inserts: $insert = array(); foreach($_SESSION['skills'] as $key => $skill) { $insert[] = "('$skill',{$_SESSION['skys'][$key]},{$_SESSION['skus'][$key]})"; } $query = 'INSERT INTO table (skill,sky,sku) VALUES ' . implode(',',$insert); //run query -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.comforeach($skills as $key => $skill) { echo "$skill - {$skys[$key]} - {$slus[$key]}\n"; }