Re: dealing with arrays

From: Date: Wed, 27 Aug 2003 14:33:43 +0000
Subject: Re: dealing with arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-160912@lists.php.net to get a copy of this message
You need to name the elements a little differently. You're on the right track with making them an array, but if I check the third box, that'll make $check[0] = 1, and if I put in a name in the first box, that'll make $name[0] = 'John'... so you have no way of relating the name from "entry one" to the checkbox in "entry one". So, the easy fix for this is to supply the key yourself. <p>Entry One <input type=text name=name[1]> <input type=text name=tel[1]> <input type=checkbox name=check[1] value=1> <p>Entry Two <input type=text name=name[1]> <input type=text name=tel[1]> <input type=checkbox name=check[1] value=1> Now, when that is submitted, only the checked values will be passed in $check.. so you can do this (assuming POST): foreach($_POST['check'] as $key => $value) { if(empty($_POST['name'][$key])) { echo "you didn't supply a name for entry $key"; } if(empty($_POST['tel'][$key])) { echo "you didn't supply a telephone number for entry $key"; } //process $_POST['name'][$key] and $_POST['tel'][$key] } Hope that helps. Sorry for the top post, but OE sucks. :) ---John Holmes... ----- Original Message ----- From: "Aris Santillan" <aris@femalenetwork.com> To: "Php (E-mail)" <php-general@lists.php.net> Sent: Tuesday, August 26, 2003 11:21 PM Subject: [PHP] dealing with arrays hi I Have <p>Entry One <input type=text name=name[]> <input type=text name=tel[]> <input type=checkbox name=check[] value=1> <p>Entry Two <input type=text name=name[]> <input type=text name=tel[]> <input type=checkbox name=check[] value=1> <p>Entry Three <input type=text name=name[]> <input type=text name=tel[]> <input type=checkbox name=check[] value=1> <p>Entry Four <input type=text name=name[]> <input type=text name=tel[]> <input type=checkbox name=check[] value=1> <p>Entry Five <input type=text name=name[]> <input type=text name=tel[]> <input type=checkbox name=check[] value=1> . i want to process entries only with checked checkbox how can i do this in php?

« previous php.general (#160912) next »