skills[cooking]
skills[flying]
skills[walking]
...
Notice there are no quotes around the skill names. Now each array element has an array key that is a name. The computer doesn't really care, but it makes it easier for you to read your code. And you now have name/value pairs. You can process the array like this:
$skillNames = array_keys($skills); foreach($skillNames as $skill) { echo 'Skill: '.$skill.' Value: '.$skills[$skill].' <br />'; }
Of course, instead of echoing you would do your validation or substitution.
On Oct 20, 2004, at 8:35 AM, Stuart Felenstein wrote:
After some back and forth posts here I had finally thought my array issue was over, but!
To review I have 30 form elements on a page 10 are skill[] 10 are sky[] 10 are slu[]
I pass them as session variables
$_SESSION['skills'] = $_POST['skill']; $_SESSION['skys'] = $_POST['sky']; $_SESSION['slus'] = $_POST['slu'];
Then when everyting is passed into a database transaction:
$skills = $_SESSION['skills']; $skys = $_SESSION['skys']; $slus = $_SESSION['slus'];
foreach($_SESSION['skills'] as $key => $skill) { $query = "INSERT INTO Profiles_skills (ProfileID, SkilCerts, NumYear, Lused) VALUES ($LID, '$skill', {$_SESSION['skys'][$key]},{$_SESSION['slus'][$key]})"; //$result = mysql_query($query);
Here is the problem:
Using (((isset($_POST["skill[]"]))?$_POST["skill[]"]:"") . "",true,true,true,true,"",false,1);
I can't seem to differentiate between the the elements because they are all labeled skill[] So basically validation isn't doing anything .
I'm thinking of finding a better way to validate , or if i change the elements to skill[1], skill[2] , what would that do to my iteration loop ?
Thank you, Stuart
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- Brent Baisley Systems Architect Landover Associates, Inc. Search & Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php