Re: [PHP] while-do +array



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
.



Relevant Pages

  • Son of Beast - 2008 - My Experience
    ... I rode the SOB for the first time in four years and obviously the ... first time since they removed the loop and changed the trains. ... roughest ride I have ever felt in my life (I thought the last time I ...
    (rec.roller-coaster)
  • Re: branch prediction optimization
    ... If you had a loop like ... head = NULL; ... although the first time through the loop will suffer. ... struct node *next; ...
    (comp.unix.programmer)
  • branch prediction optimization
    ... I guess some processors have special branch instructions where you can ... If you had a loop like ... tail = NULL; ... although the first time through the loop will suffer. ...
    (comp.unix.programmer)
  • Re: Crookshanks and Victor Krum, and Hermione
    ... without a time-turner and witnessed many things as a silent ... first time you read through it. ... some sort of weird loop that keeps going. ... selection to time travel. ...
    (alt.fan.harry-potter)
  • fgetcsv returns false in dynamic read vs. hard-coded read ??
    ... I am working with directories in PHP for the first time. ... that I've changed multiple times to try different things. ... displaying each file name and it can display the name, ... I've even tried setting a for loop and hard coding each file name ...
    (comp.lang.php)