Re: [PHP] Another hand wringer

2007-02-20 Thread Richard Lynch
On Sun, February 18, 2007 3:06 pm, jekillen wrote:
 iterator $i and given a_$i+1 names. If I test for the field names
 on post literally, a_1, a_2, a_...n, the values are getting posted
 properly.

Save yourself a LOT of headaches and index-munging and just do this:

input namea[1] value=whatever /
input namea[2] value=whatever /
input namea[3] value=whatever /

Then:
$a = $_POST['a'];
//$a is now an array with indices 1, 2, and 3.

The time you spend re-writing it this way will be paid off almost
immediately.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Another hand wringer

2007-02-18 Thread jekillen

Hello;
I am having trouble with a loop in scripts run under
php v5.1.2.

I have produced a form in a web page that has a variable number
of text fields. These fields represent the result of opening a file
and populating the fields with the corresponding value data found
in the file. The field names are generated in a php loop using an
iterator $i and given a_$i+1 names. If I test for the field names
on post literally, a_1, a_2, a_...n, the values are getting posted
properly.
Then when I run through a loop looking for $_POST[a_$z]
(where $z = $i +1) only one $_POST value with this name
series is processes and the loop quits.
Here is the post processing code at this stage of the script:

$edata = array();
$part = '';
$flen = '';
$file = '';
if($_POST['section'])
  {
   $part = $_POST['section']; // target file section
   $flen = $_POST['flen'];// length of text field group, shows to 
be the correct number

   $file = $_POST['df'];  // file to work on
   $z = 1;
   switch($part)
 {
  case 'name':
  /*
a_1, a_2 etc are field names
printing these values shows that all the fields are being 
posted properly

array_push($edata, $_POST[a_1]);
array_push($edata, $_POST[a_2]);
array_push($edata, $_POST[a_3]);
array_push($edata, $_POST[a_4]);
   could be as few as 1 and as many as 13 fields
  */
  for($i = 0; $i  count($flen); $i++)
  {
   array_push($edata, $_POST[a_$z]); // this loop 
terminates on the first iteration.
   print $_POST[a_$z].'br'; // only prints the first in 
the series.

   $z++;
  };
  //edit_pa_rec($edata, $file, $flen, $part);
  break; - more cases with similar code
I want to avoid hard coding the $_POST variables
so, question, is this:
A: a bug?
B: $_POST data is getting dropped in the loop?
C: Something else is wrong with my code?
Thanks in advance
Jeff K

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Another hand wringer

2007-02-18 Thread Matt Zandstra
Looks to me as if you're treating $flen as an array in one place and as a 
value in another:


String here:

  $flen = $_POST['flen'];// length of text field group, shows to be the


Array here:

 for($i = 0; $i  count($flen); $i++)


Remove the count() and you'll probably get what you expect.

hth


On Sun, 18 Feb 2007, jekillen wrote:


Hello;
I am having trouble with a loop in scripts run under
php v5.1.2.

I have produced a form in a web page that has a variable number
of text fields. These fields represent the result of opening a file
and populating the fields with the corresponding value data found
in the file. The field names are generated in a php loop using an
iterator $i and given a_$i+1 names. If I test for the field names
on post literally, a_1, a_2, a_...n, the values are getting posted
properly.
Then when I run through a loop looking for $_POST[a_$z]
(where $z = $i +1) only one $_POST value with this name
series is processes and the loop quits.
Here is the post processing code at this stage of the script:

$edata = array();
$part = '';
$flen = '';
$file = '';
if($_POST['section'])
 {
  $part = $_POST['section']; // target file section
  $flen = $_POST['flen'];// length of text field group, shows to be the 
correct number

  $file = $_POST['df'];  // file to work on
  $z = 1;
  switch($part)
{
 case 'name':
 /*
   a_1, a_2 etc are field names
   printing these values shows that all the fields are being posted 
properly

   array_push($edata, $_POST[a_1]);
   array_push($edata, $_POST[a_2]);
   array_push($edata, $_POST[a_3]);
   array_push($edata, $_POST[a_4]);
  could be as few as 1 and as many as 13 fields
 */
 for($i = 0; $i  count($flen); $i++)
 {
  array_push($edata, $_POST[a_$z]); // this loop terminates on 
the first iteration.
  print $_POST[a_$z].'br'; // only prints the first in the 
series.

  $z++;
 };
 //edit_pa_rec($edata, $file, $flen, $part);
 break; - more cases with similar code
I want to avoid hard coding the $_POST variables
so, question, is this:
A: a bug?
B: $_POST data is getting dropped in the loop?
C: Something else is wrong with my code?
Thanks in advance
Jeff K




--
getInstance()
http://www.getinstance.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php