RE: [PHP] selecting from an array based on form content
$strandx is defined with code at the top of the page, as follows $strandx = array('English' => array('Reading', 'Writing','Oral and Visual Communication'), 'Mathematics' => array('Number Sense and Numeration', 'Measurement', 'Geometry and Spatial Sense','Patterning and Algebra','Data Management and Probability')); Peter Gumbrell [EMAIL PROTECTED] -Original Message- From: John W. Holmes [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 02, 2003 2:50 PM To: 'Peter Gumbrell'; [EMAIL PROTECTED] Subject: RE: [PHP] selecting from an array based on form content Where do you define the $strandx array? What is it's value? ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ > -Original Message- > From: Peter Gumbrell [mailto:[EMAIL PROTECTED]] > Sent: Sunday, February 02, 2003 2:08 PM > To: [EMAIL PROTECTED] > Subject: RE: [PHP] selecting from an array based on form content > > Thanks for the suggestion, John. When I implement your code, however, I > get > an error saying > Warning: Invalid argument supplied for foreach() in > home/student/peter/public_html/week4.php on line 153 > > where line 153 is > > foreach($strandx[$subject] as $strandy ) > > This is the code as I have it now: > > switch($_POST['fsubject']) > { > case "English": > $subject = "English"; > break; > case "Mathematics": > $subject = "Mathematics"; > break; > } > Print "Now select the strands for Grade $grades: > $subject:"; > > print ""; > print "$subject"; //this tells me that I have the correct value > foreach($strandx[$subject] as $strandy ) > { > //print " ".$subject.".\n"; > > > print " \n"; > > foreach( $strandy as $str ) > > { print ""; > checkbox("fstrand[]",$strandx,$str,0,0); > print "\n"; > } > > Any help would again be appreciated. > > Peter > -Original Message- > From: John W. Holmes [mailto:[EMAIL PROTECTED]] > Sent: Sunday, February 02, 2003 1:28 PM > To: 'Peter Gumbrell'; [EMAIL PROTECTED] > Subject: RE: [PHP] selecting from an array based on form content > > > > The following code loops through a multidimensional array, printing > the > > subject heading and then the strand: > > > > foreach( $strandx as $subjectx=>$strandy ) > > { > > print " ".$subjectx.".\n"; > > > > > > print " \n"; > > asort( $strandy ); // sorts the strands > > foreach( $strandy as $str ) > > > > { print ""; > > checkbox("fstrand[]",$subjectx,$str,0,0); > > print "\n"; > > } > > print " \n"; > > } > > print "\n"; > > > > This is the array so far: > > $strandx = array('English' => array('Reading', 'Writing','Oral and > Visual > > Communication'), > > 'Mathematics' => array('Number Sense and Numeration', 'Measurement', > > 'Geometry and Spatial Sense','Patterning and Algebra','Data Management > and > > Probability')); > > > > I would like to limit the subject and strand being printed based on > the > > subject selected in a form. So, for example, if "English" is selected > in > > the > > form, only the subject name and the strands for English would be > > published. > > Could someone please help me with the code for this. > > Since you already know $subjectx (English or Math), then just use that > value in your foreach() loop... > > Foreach($strandx[$subjectx] as $strandy) > > Where $subjectx would come from your form. Provide some validation > first. > > So something like this: > > //Many ways to do this, just validate > //whatever is coming from your form > //matches a key in $strandx > switch($_POST['subject']) > { > case "English" > $subject = "English" > break; > default: > $subject = "Mathematics"; > break; > } > > print " ".$subject.".\n"; > foreach( $strandx[$subject] as $strandy ) > { > print " \n"; > asort($strandy ); // sorts the strands > foreach( $strandy as $str ) > { > print ""; > checkbox("fstrand[]",$subjectx,$str,0,0); > print "\n"; > } > print " \n"; > } > print "\n"; > > ---John W. Holmes... > > PHP Architect - A monthly magazine for PHP Professionals. Get your copy > today. http://www.phparch.com/ > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] selecting from an array based on form content
Where do you define the $strandx array? What is it's value? ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ > -Original Message- > From: Peter Gumbrell [mailto:[EMAIL PROTECTED]] > Sent: Sunday, February 02, 2003 2:08 PM > To: [EMAIL PROTECTED] > Subject: RE: [PHP] selecting from an array based on form content > > Thanks for the suggestion, John. When I implement your code, however, I > get > an error saying > Warning: Invalid argument supplied for foreach() in > home/student/peter/public_html/week4.php on line 153 > > where line 153 is > > foreach($strandx[$subject] as $strandy ) > > This is the code as I have it now: > > switch($_POST['fsubject']) > { > case "English": > $subject = "English"; > break; > case "Mathematics": > $subject = "Mathematics"; > break; > } > Print "Now select the strands for Grade $grades: > $subject:"; > > print ""; > print "$subject"; //this tells me that I have the correct value > foreach($strandx[$subject] as $strandy ) > { > //print " ".$subject.".\n"; > > > print " \n"; > > foreach( $strandy as $str ) > > { print ""; > checkbox("fstrand[]",$strandx,$str,0,0); > print "\n"; > } > > Any help would again be appreciated. > > Peter > -Original Message- > From: John W. Holmes [mailto:[EMAIL PROTECTED]] > Sent: Sunday, February 02, 2003 1:28 PM > To: 'Peter Gumbrell'; [EMAIL PROTECTED] > Subject: RE: [PHP] selecting from an array based on form content > > > > The following code loops through a multidimensional array, printing > the > > subject heading and then the strand: > > > > foreach( $strandx as $subjectx=>$strandy ) > > { > > print " ".$subjectx.".\n"; > > > > > > print " \n"; > > asort( $strandy ); // sorts the strands > > foreach( $strandy as $str ) > > > > { print ""; > > checkbox("fstrand[]",$subjectx,$str,0,0); > > print "\n"; > > } > > print " \n"; > > } > > print "\n"; > > > > This is the array so far: > > $strandx = array('English' => array('Reading', 'Writing','Oral and > Visual > > Communication'), > > 'Mathematics' => array('Number Sense and Numeration', 'Measurement', > > 'Geometry and Spatial Sense','Patterning and Algebra','Data Management > and > > Probability')); > > > > I would like to limit the subject and strand being printed based on > the > > subject selected in a form. So, for example, if "English" is selected > in > > the > > form, only the subject name and the strands for English would be > > published. > > Could someone please help me with the code for this. > > Since you already know $subjectx (English or Math), then just use that > value in your foreach() loop... > > Foreach($strandx[$subjectx] as $strandy) > > Where $subjectx would come from your form. Provide some validation > first. > > So something like this: > > //Many ways to do this, just validate > //whatever is coming from your form > //matches a key in $strandx > switch($_POST['subject']) > { > case "English" > $subject = "English" > break; > default: > $subject = "Mathematics"; > break; > } > > print " ".$subject.".\n"; > foreach( $strandx[$subject] as $strandy ) > { > print " \n"; > asort($strandy ); // sorts the strands > foreach( $strandy as $str ) > { > print ""; > checkbox("fstrand[]",$subjectx,$str,0,0); > print "\n"; > } > print " \n"; > } > print "\n"; > > ---John W. Holmes... > > PHP Architect - A monthly magazine for PHP Professionals. Get your copy > today. http://www.phparch.com/ > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] selecting from an array based on form content
Thanks for the suggestion, John. When I implement your code, however, I get an error saying Warning: Invalid argument supplied for foreach() in home/student/peter/public_html/week4.php on line 153 where line 153 is foreach($strandx[$subject] as $strandy ) This is the code as I have it now: switch($_POST['fsubject']) { case "English": $subject = "English"; break; case "Mathematics": $subject = "Mathematics"; break; } Print "Now select the strands for Grade $grades: $subject:"; print ""; print "$subject"; //this tells me that I have the correct value foreach($strandx[$subject] as $strandy ) { //print " ".$subject.".\n"; print " \n"; foreach( $strandy as $str ) { print ""; checkbox("fstrand[]",$strandx,$str,0,0); print "\n"; } Any help would again be appreciated. Peter -Original Message- From: John W. Holmes [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 02, 2003 1:28 PM To: 'Peter Gumbrell'; [EMAIL PROTECTED] Subject: RE: [PHP] selecting from an array based on form content > The following code loops through a multidimensional array, printing the > subject heading and then the strand: > > foreach( $strandx as $subjectx=>$strandy ) > { > print " ".$subjectx.".\n"; > > > print " \n"; > asort( $strandy ); // sorts the strands > foreach( $strandy as $str ) > > { print ""; > checkbox("fstrand[]",$subjectx,$str,0,0); > print "\n"; > } > print " \n"; > } > print "\n"; > > This is the array so far: > $strandx = array('English' => array('Reading', 'Writing','Oral and Visual > Communication'), > 'Mathematics' => array('Number Sense and Numeration', 'Measurement', > 'Geometry and Spatial Sense','Patterning and Algebra','Data Management and > Probability')); > > I would like to limit the subject and strand being printed based on the > subject selected in a form. So, for example, if "English" is selected in > the > form, only the subject name and the strands for English would be > published. > Could someone please help me with the code for this. Since you already know $subjectx (English or Math), then just use that value in your foreach() loop... Foreach($strandx[$subjectx] as $strandy) Where $subjectx would come from your form. Provide some validation first. So something like this: //Many ways to do this, just validate //whatever is coming from your form //matches a key in $strandx switch($_POST['subject']) { case "English" $subject = "English" break; default: $subject = "Mathematics"; break; } print " ".$subject.".\n"; foreach( $strandx[$subject] as $strandy ) { print " \n"; asort($strandy ); // sorts the strands foreach( $strandy as $str ) { print ""; checkbox("fstrand[]",$subjectx,$str,0,0); print "\n"; } print " \n"; } print "\n"; ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] selecting from an array based on form content
> The following code loops through a multidimensional array, printing the > subject heading and then the strand: > > foreach( $strandx as $subjectx=>$strandy ) > { > print " ".$subjectx.".\n"; > > > print " \n"; > asort( $strandy ); // sorts the strands > foreach( $strandy as $str ) > > { print ""; > checkbox("fstrand[]",$subjectx,$str,0,0); > print "\n"; > } > print " \n"; > } > print "\n"; > > This is the array so far: > $strandx = array('English' => array('Reading', 'Writing','Oral and Visual > Communication'), > 'Mathematics' => array('Number Sense and Numeration', 'Measurement', > 'Geometry and Spatial Sense','Patterning and Algebra','Data Management and > Probability')); > > I would like to limit the subject and strand being printed based on the > subject selected in a form. So, for example, if "English" is selected in > the > form, only the subject name and the strands for English would be > published. > Could someone please help me with the code for this. Since you already know $subjectx (English or Math), then just use that value in your foreach() loop... Foreach($strandx[$subjectx] as $strandy) Where $subjectx would come from your form. Provide some validation first. So something like this: //Many ways to do this, just validate //whatever is coming from your form //matches a key in $strandx switch($_POST['subject']) { case "English" $subject = "English" break; default: $subject = "Mathematics"; break; } print " ".$subject.".\n"; foreach( $strandx[$subject] as $strandy ) { print " \n"; asort($strandy ); // sorts the strands foreach( $strandy as $str ) { print ""; checkbox("fstrand[]",$subjectx,$str,0,0); print "\n"; } print " \n"; } print "\n"; ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] selecting from an array based on form content
The following code loops through a multidimensional array, printing the subject heading and then the strand: foreach( $strandx as $subjectx=>$strandy ) { print " ".$subjectx.".\n"; print " \n"; asort( $strandy ); // sorts the strands foreach( $strandy as $str ) { print ""; checkbox("fstrand[]",$subjectx,$str,0,0); print "\n"; } print " \n"; } print "\n"; This is the array so far: $strandx = array('English' => array('Reading', 'Writing','Oral and Visual Communication'), 'Mathematics' => array('Number Sense and Numeration', 'Measurement', 'Geometry and Spatial Sense','Patterning and Algebra','Data Management and Probability')); I would like to limit the subject and strand being printed based on the subject selected in a form. So, for example, if "English" is selected in the form, only the subject name and the strands for English would be published. Could someone please help me with the code for this. Many thanks, Peter Gumbrell [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php