[PHP] Re: Foreach Array Help

2003-10-14 Thread Rob Adams

Jed R. Brubaker [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Okay, total newbie when it comes to arrays, and I could really use some
 help. I sure this will be an easy one for you veterans out there.

 Here is the array ($code):
 array(2) {
   [total]=
   int(1)
   [assign]=
   array(1) {
 [1]=
 array(3) {
   [type]=
   string(10) Transcript
   [rows]=
   string(3) 603
   [codeapply]=
   array(1) {
 [1]=
 array(3) {
   [codeset]=
   string(23) FFT 6 Level Code System
   [code_rows]=
   string(3) 302
   [code_complete]=
   string(1) 2
 }
   }
 }
   }
 }

 Here is the output code:
 foreach ($this-code['assign'] as $assign = $details)
 {
 foreach ($assign['codeapply'] as $codeapply = $ca_details)
 {
 echo tr;
 echotd;
 echo$details['type']. .$assign;
 echo/a;
 echo/td;
 echotd;
 echo$ca_details['codeset'];
 echo/td;
 echotd;
 echo
 $ca_details['code_complete']./.$ca_details['code_rows']. Items Coded;
 echo/td;
 echotd;
 printf  ( %.0d%%,
 ($ca_details['code_complete']/$ca_details['code_rows'])*100);
 echo/td;
 echo /tr;
 }
 }

 Output error:
 Warning: Cannot use a scalar value as an array
 Warning: Invalid argument supplied for foreach()

 Conceptually and practically I have been struggling with how to navigate
 levels of the arrays which are defined by a variable (e.g.
 $code['assign'][$i] for the assign ID and $code['assign'][$i][$j] for the

if $code['assign'][$i] has some integer value, then it is not an array.
if $code['assign'][$i][$j] has some integer value, then $code['assign'][$i]
is an array.

You have two mutually exclusive possibilities there.

Probably, what you want to do is something like:

$code['assign'][$i]['aid'] = (assign ID);
$code['assign'][$i][$j] = (whatever you want here);

(which, for simplicity, translates into something like:)

$code['assign'][1]['aid'] = 1;
$code['assign'][1]['1'] = 11;
$code['assign'][1]['2'] = 12;
$code['assign'][1]['3'] = 13;
$code['assign'][1]['4'] = 14;
$code['assign'][1]['5'] = 15;
etc.

  -- Rob




 codeapply ID on the assign ID).

 Thanks in advance!

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



[PHP] Re: Foreach Array Help

2003-10-14 Thread Jed R. Brubaker
First of all, thanks for the response.

Here is where I am getting lost:
In $code['assign'][1] - 1 is the assignment ID, and I would like the array
to be able to hold a billion of these different assignments all with
conceivably a billion codeapply ID as in $code['assign'][1]['codeapply'][3],
where 3 is the codeapply value. In other words, because each of these
items directly under assign and codeapply are arrays because they hold
sub-info, I have made the keys of these items the values.

So - am I approaching this whole array thing wrong?

Thanks.

Rob Adams [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

 Jed R. Brubaker [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  Okay, total newbie when it comes to arrays, and I could really use some
  help. I sure this will be an easy one for you veterans out there.
 
  Here is the array ($code):
  array(2) {
[total]=
int(1)
[assign]=
array(1) {
  [1]=
  array(3) {
[type]=
string(10) Transcript
[rows]=
string(3) 603
[codeapply]=
array(1) {
  [1]=
  array(3) {
[codeset]=
string(23) FFT 6 Level Code System
[code_rows]=
string(3) 302
[code_complete]=
string(1) 2
  }
}
  }
}
  }
 
  Here is the output code:
  foreach ($this-code['assign'] as $assign = $details)
  {
  foreach ($assign['codeapply'] as $codeapply = $ca_details)
  {
  echo tr;
  echotd;
  echo$details['type']. .$assign;
  echo/a;
  echo/td;
  echotd;
  echo$ca_details['codeset'];
  echo/td;
  echotd;
  echo
  $ca_details['code_complete']./.$ca_details['code_rows']. Items
Coded;
  echo/td;
  echotd;
  printf  ( %.0d%%,
  ($ca_details['code_complete']/$ca_details['code_rows'])*100);
  echo/td;
  echo /tr;
  }
  }
 
  Output error:
  Warning: Cannot use a scalar value as an array
  Warning: Invalid argument supplied for foreach()
 
  Conceptually and practically I have been struggling with how to navigate
  levels of the arrays which are defined by a variable (e.g.
  $code['assign'][$i] for the assign ID and $code['assign'][$i][$j] for
the

 if $code['assign'][$i] has some integer value, then it is not an array.
 if $code['assign'][$i][$j] has some integer value, then
$code['assign'][$i]
 is an array.

 You have two mutually exclusive possibilities there.

 Probably, what you want to do is something like:

 $code['assign'][$i]['aid'] = (assign ID);
 $code['assign'][$i][$j] = (whatever you want here);

 (which, for simplicity, translates into something like:)

 $code['assign'][1]['aid'] = 1;
 $code['assign'][1]['1'] = 11;
 $code['assign'][1]['2'] = 12;
 $code['assign'][1]['3'] = 13;
 $code['assign'][1]['4'] = 14;
 $code['assign'][1]['5'] = 15;
 etc.

   -- Rob




  codeapply ID on the assign ID).
 
  Thanks in advance!

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



[PHP] Re: Foreach Array Help

2003-10-14 Thread Jed R. Brubaker
Never mind - I figured it out.

While I was traversing like this:

foreach ($this-code['assign'] as $assign = $details)
{
foreach ($assign['codeapply'] as $codeapply = $ca_details)
{

}
}

I had set up $assign to be the key value, and likewise not be an array. I
changed it to:

foreach ($this-code['assign'] as $assign = $details)
{
foreach ($details['codeapply'] as $codeapply = $ca_details)
{

}
}

and it worked beautifully. Thanks to all of you who got me going in the
right direction.



Jed R. Brubaker [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Okay, total newbie when it comes to arrays, and I could really use some
 help. I sure this will be an easy one for you veterans out there.

 Here is the array ($code):
 array(2) {
   [total]=
   int(1)
   [assign]=
   array(1) {
 [1]=
 array(3) {
   [type]=
   string(10) Transcript
   [rows]=
   string(3) 603
   [codeapply]=
   array(1) {
 [1]=
 array(3) {
   [codeset]=
   string(23) FFT 6 Level Code System
   [code_rows]=
   string(3) 302
   [code_complete]=
   string(1) 2
 }
   }
 }
   }
 }

 Here is the output code:
 foreach ($this-code['assign'] as $assign = $details)
 {
 foreach ($assign['codeapply'] as $codeapply = $ca_details)
 {
 echo tr;
 echotd;
 echo$details['type']. .$assign;
 echo/a;
 echo/td;
 echotd;
 echo$ca_details['codeset'];
 echo/td;
 echotd;
 echo
 $ca_details['code_complete']./.$ca_details['code_rows']. Items Coded;
 echo/td;
 echotd;
 printf  ( %.0d%%,
 ($ca_details['code_complete']/$ca_details['code_rows'])*100);
 echo/td;
 echo /tr;
 }
 }

 Output error:
 Warning: Cannot use a scalar value as an array
 Warning: Invalid argument supplied for foreach()

 Conceptually and practically I have been struggling with how to navigate
 levels of the arrays which are defined by a variable (e.g.
 $code['assign'][$i] for the assign ID and $code['assign'][$i][$j] for the
 codeapply ID on the assign ID).

 Thanks in advance!

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



[PHP] Re: Foreach Array Help

2003-10-14 Thread Rob Adams

Jed R. Brubaker [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 First of all, thanks for the response.

 Here is where I am getting lost:
 In $code['assign'][1] - 1 is the assignment ID, and I would like the
array
 to be able to hold a billion of these different assignments all with
 conceivably a billion codeapply ID as in
$code['assign'][1]['codeapply'][3],
 where 3 is the codeapply value. In other words, because each of these
 items directly under assign and codeapply are arrays because they hold
 sub-info, I have made the keys of these items the values.

 So - am I approaching this whole array thing wrong?

I still don't understand exactly what you want to do, but see below...


 Thanks.

 Rob Adams [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 
  Jed R. Brubaker [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
   Okay, total newbie when it comes to arrays, and I could really use
some
   help. I sure this will be an easy one for you veterans out there.
  
   Here is the array ($code):
   array(2) {
 [total]=
 int(1)
 [assign]=
 array(1) {
   [1]=
   array(3) {
 [type]=
 string(10) Transcript
 [rows]=
 string(3) 603
 [codeapply]=
 array(1) {
   [1]=
   array(3) {
 [codeset]=
 string(23) FFT 6 Level Code System
 [code_rows]=
 string(3) 302
 [code_complete]=
 string(1) 2
   }
 }
   }
 }
   }
  
   Here is the output code:
   foreach ($this-code['assign'] as $assign = $details)
   {

Here, $assign is a key from the $this-code['assign'] array.  Since,
according to the array above, assign has only one element, and the key to
that element is '1', $assign will always be one and this code run through
just once.  $details is an array with three key/value pairs.  They are
'type' = 'Transcript', 'rows' = '603', and 'codeapply' = (an array).

   foreach ($assign['codeapply'] as $codeapply =
$ca_details)
   {

So, looking at this it looks like what you actually want to do is:
  foreach($details['codeapply'] ... )

$details['codeapply'] has a single key/value pair, which is ('1' = (an
array)).  This array can be reached by using $ca_details['codeset']... etc.

   echo tr;
   echotd;
   echo$details['type']. .$assign;
   echo/a;
   echo/td;
   echotd;
   echo$ca_details['codeset'];
   echo/td;
   echotd;
   echo
   $ca_details['code_complete']./.$ca_details['code_rows']. Items
 Coded;
   echo/td;
   echotd;
   printf  ( %.0d%%,
   ($ca_details['code_complete']/$ca_details['code_rows'])*100);
   echo/td;
   echo /tr;
   }
   }
  
   Output error:
   Warning: Cannot use a scalar value as an array
   Warning: Invalid argument supplied for foreach()
  
   Conceptually and practically I have been struggling with how to
navigate
   levels of the arrays which are defined by a variable (e.g.
   $code['assign'][$i] for the assign ID and $code['assign'][$i][$j] for
 the
 
  if $code['assign'][$i] has some integer value, then it is not an array.
  if $code['assign'][$i][$j] has some integer value, then
 $code['assign'][$i]
  is an array.
 
  You have two mutually exclusive possibilities there.
 
  Probably, what you want to do is something like:
 
  $code['assign'][$i]['aid'] = (assign ID);
  $code['assign'][$i][$j] = (whatever you want here);
 
  (which, for simplicity, translates into something like:)
 
  $code['assign'][1]['aid'] = 1;
  $code['assign'][1]['1'] = 11;
  $code['assign'][1]['2'] = 12;
  $code['assign'][1]['3'] = 13;
  $code['assign'][1]['4'] = 14;
  $code['assign'][1]['5'] = 15;
  etc.
 
-- Rob
 
 
 
 
   codeapply ID on the assign ID).
  
   Thanks in advance!

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