[PHP] count() multidimensional array

2001-05-19 Thread Dean Martin

I have a multidimensional array being created by a form.  Most fields are
pre-populated with a few that people can add to the list.  There is a box
beside each row that they can check whether that item is in or not.

My code to list only the rows that were checked is this..

for ($j=1 ; $j=5; $j++)
{
for ($i=0 ; $icount($check[$j]) ; $i++)
{
if ($check[$j][$i] == 1)//was boxed checked?
{
$message .= $pre[$j][$i]. .$post[$j][$i]. .$name[$j][$i].
.$city[$j][$i]. .$state[$j][$i]\n;
}
}
}

This code is creating an endless loop and times out the server with memory
overruns.

What am I missing?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] count() multidimensional array

2001-05-19 Thread Chris Lee

can't say for sure, but a good guess is some problems with undefined vars.
try using fforeach insted, its alot simpler.

?php
foreach($check as $j_pos = $j_val)
foreach($check[$j_pos] as $i_pos = $i_val)
$message .= {$pre[$j_pos][$i_pos]} {$post[$j_pos][$i_pos]}
{$name[$j_pos][$i_pos]} {$city[$j_pos][$i_pos]} {$state[$j_pos][$i_pos]}
\n;
?

input type='checkbox' name='check[0][0]' value='1' checked
input type='checkbox' name='check[0][1]' value='1'
input type='checkbox' name='check[1][0]' value='1' checked
input type='checkbox' name='check[1][1]' value='1' checked
input type='checkbox' name='check[2][0]' value='1'
input type='checkbox' name='check[2][1]' value='1'
input type='checkbox' name='check[3][0]' value='1'
input type='checkbox' name='check[3][1]' value='1' checked
ok, now we have an example,

$check[0][0]
$check[1][0]
$check[1][1]
$check[3][1]

are set, the others are not. you can see why 'for($c = 0; $c 
count($check); $c++)' will not work. foreach simplifies things alot. you
also do not need to check
'if ($check[$j][$i] == 1)' becase if it is set at all, then it 'had' to be
checked.

Is this what you were looking for ?

--

  Chris Lee
  [EMAIL PROTECTED]



Dean Martin [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 I have a multidimensional array being created by a form.  Most fields are
 pre-populated with a few that people can add to the list.  There is a box
 beside each row that they can check whether that item is in or not.

 My code to list only the rows that were checked is this..

 for ($j=1 ; $j=5; $j++)
 {
 for ($i=0 ; $icount($check[$j]) ; $i++)
 {
 if ($check[$j][$i] == 1)//was boxed checked?
 {
 $message .= $pre[$j][$i]. .$post[$j][$i]. .$name[$j][$i].
 .$city[$j][$i]. .$state[$j][$i]\n;
 }
 }
 }

 This code is creating an endless loop and times out the server with memory
 overruns.

 What am I missing?


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] count() multidimensional array

2001-05-19 Thread Hugh Bothwell

Dean Martin [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 My code to list only the rows that were checked is this..

 for ($j=1 ; $j=5; $j++)
SNIP
 This code is creating an endless loop and times out the server with memory
 overruns.

 What am I missing?

In the end-loop condition, you're using assignment ('=') instead of if-equal
('==').

Effectively, the loop runs until 5 == 0  ;-)



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]