Re: while-do +array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 31/10/2007, Steven Macintyre <steven@xxxxxxxxxxxxxxxxxxxxx> wrote:
> Hiya,
>
> I have the following code ... which only seems to result in one item ...
> which is incorrect ... can anyone spot my problem?
>
>         if ($armbase != "") {
>                 $options = explode(",", $armbase);
>                 $text .=  '<table ><tr>';
>                 $get_endRow = 0;
>                 $get_columns = 8;
>                 $get_hloopRow1 = 0;
>
>                 do {
>                         if($get_endRow == 0  && $get_hloopRow1++ != 0) {
>                                 $text .= '<tr>';
>                                 $text .= '<td valign="top" width="60">';
>                                 $text .= "<img
> src='".e_BASE."images/options/armbase/".$value."'>";
>                                 $text .= '</td>';
>                                 $get_endRow++;
>                         }
>                         if($get_endRow >= $get_columns) {
>                                 $text .=  '</tr>';
>                                 $get_endRow = 0;
>                         }
>                 } while(list($key,$value) = each($options));

The first time around the loop, both $key and $value are undefined, as
you're not setting them until the end condition.

But that's not a big deal as nothing gets done first time through the
loop except for $get_hloopRow1 getting incremented.

The next time through the loop, because $get_hloopRow1 is now not
zero, the first conditional gets executed. You add some html and the
first value from the array to $text to the string and incremenent
$get_endRow.

All subsequent times through the loop, nothing gets done because the
$get_endRow == 0 condition fails. $get_endRow never gets incrememented
again.

that help at all?

-robin

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux