Forum Moderators: coopster
It starts with this in my index:
$display = $page->_init($select);
In the _init routine I'm parsing the request and begin gathering what I need from the database. Once I know how many rows to build, I go into a foreach loop and put together all the pieces. The foreach loop contains calls to specific functions to accomplish this. Each of the functions will contain something like this :
$this->$page .= "blah";
The result that I'm getting is that only the last row is returned. I can verify that all the information is getting processed, but not all of it getting returned. In fact, it appears that each consecutive row is overwriting the previous row.
Page is defined in my object like this, preceeding any functions:
var $page;
My usage of .= is based on the belief that $this->$page will accumulate everything as I work throught the loop. I'm obvioulsy mistaken, can someone enlighten me?
$this->$page .= "blah";
... the syntax looks incorrect. You should not have that dollar sign there if I understand how you intend to use the variable.
function _init($param) {
// process param options
// and return an array of all
// items on this page
foreach ($list as $k => $v) {
foreach ($v as $k2 => $v2) {
$item_array[] = $v2;
// alternate left to right
if ($k2 == 9) {
if(($k % 2) == 1) {
$this->_buildLeftContent($item_array);
} else {
$this->_buildRightContent($item_array);
}
$item_array = array();
}
}
}
return $this->$page;
}
I'm ready to toss this mess in the bit bucket and start over with a clean screen.
In case it was missed earlier, the variable $page is declared in the class as a public variable. All of that works, meaning, I do get the page output that I expect, sort of. The loop is the problem, where consecutive loops will overwrite the previous output, and I'm only returning the results from the last iteration of the loop.
This is such a basic problem, I can't believe I've spent 4 days so far. Is it Friday yet? (Now I'm going to go have a look at Henry's suggestion)