I had some code that worked fine for several weeks, and then yesterday
it stopped working. I'm not sure what I did. Nor can I make out why it
isn't working. I'm running a query that should return 3 items from the
database. I then get a count of the return, which correctly tells me
that I've got 3 items. I then go into a for loop which I expect to
loop 3 times and print out the 3 items. Here is where things get
strange: it loops 3 times and prints out the same item all 3 times.
More so, the 2nd and 3rd time it complains that it is not getting an
array (meaning it should have nothing to print, yet it prints. If
anyone can see the error I've made, I'd be damned grateful
inside a function called listAll, I've got this:
// 12-05-03 - I originally used the "GetAllOfTy pe" query, but now I
realize I only
// need ids, so instead we'll use the GetAllOfTypeJus tIds
$selectObject = & $controllerForA ll->getObject("McS elect");
$selectObject->setQueryObject ("GetAllOfTypeJ ustIds");
$selectObject->setInfoToBeSou ght($type);
$selectObject->getInfo();
$howMany = $selectObject->getCountOfRetu rn();
for ($i=0; $i < $howMany; $i++) {
$row = null;
$row = $selectObject->getRowAsArrayW ithStringIndex( );
if (is_array($row) ) {
extract($row);
$arrangementObj ect->setControlPane lCbId($cbId);
$controllerForA ll->getArrangement ($arrangement);
} else {
$r = $i + 1;
$resultsObject->addToErrorResu lts("In the function listAll(), we
expect to print out $howMany items, yet for some reason on attempt $r
we did not get an array back from the data as an array.");
}
}
Inside of the select object, I've got this:
/**
* 11-04-03 - wrapper of getter
* We take the resource that points to the returned dataset and feed
it into a method of $formatDatastor eResults.
* We are using the resource pointer to the returned dataset to fetch
the next row and return it with a string index
*/
function getRowAsArrayWi thStringIndex() {
$row = array();
if (is_resource($t his->dsResultPointe r)) {
$row = $this->getDataObjec t->getRowAsArrayW ithStringIndex( &$this->dsResultPointe r);
if (is_array($row) ) {
$className = get_class($this->getDataObject) ;
$this->resultsObjec t->debugNotes(" In
getRowAsArrayWi thStringIndex() , in the class McSelect, we expected the
data object $className to return a row of data to us (as an array),
and it has.");
return $row;
} else {
$className = get_class($this->getDataObject) ;
$this->resultsObjec t->addToErrorResu lts("In
getRowAsArrayWi thStringIndex() , in the class McSelect, we expected the
data object '$className' to return a row of data to us, but it has
not.");
}
} else {
$this->resultsObjec t->addToErrorResu lts("In
getRowAsArrayWi thStringIndex() , in the class McSelect, we looked for
the object's resource pointer to a database return, but the select
object didn't have one.");
}
}
Inside the getData object, I've got this:
function getRowAsArrayWi thStringIndex(& $dsResultPointe r) {
$array = $this->getDataObjec t->getRowAsArrayW ithStringIndex( &$dsResultPoint er);
$className = get_class($this->getDataObject) ;
if (is_array($arra y)) {
$this->resultsObjec t->debugNotes(" In
getRowAsArrayWi thStringIndex() , in the class McGetDatastoreR esults, we
expected the data object '$className' to return a row of data to us as
an array, and it has.");
return $array;
} else {
$this->resultsObjec t->addToErrorResu lts("In
getRowAsArrayWi thStringIndex() , in the class McGetDatastoreR esults, we
expected the data object '$className' to return a row of data to us as
an array, but it has not.");
}
}
Inside the get datastore connector object, I've got this:
/**
* 11-04-03 - obviously, this is just a wrapper for a method in the
queryObject
* We take the resource that points to the returned dataset and feed
it into a method of $formatDatastor eResults.
* We are using the resource pointer to the returned dataset to fetch
the next row and return it with a string index
*
* @param - $dsResultPointe r - this is a resource pointer, pointing to
the data returned from the last SELECT call
* to the datastore.
*
* returns array - 1 dimensional
*/
function getRowAsArrayWi thStringIndex(& $dsResultPointe r) {
if (is_resource($d sResultPointer) ) {
$oneDimensional Array =
$this->formatDatastor eResults->dsRowIntoArray WithStringIndex (&$dsResultPoin ter);
$className = get_class($this->formatDatastor eResults);
if (is_array($oneD imensionalArray )) {
$this->resultsObjec t->debugNotes(" In
getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsMysql, we expected the format object '$className'
to return a row of data as an array, and it did.");
$oneDimensional Array =
$this->filterDataObje ct->thisVisitorIsA llowedToViewThi sEntry($oneDime nsionalArray);
$filterName = get_class($this->filterDataObje ct);
if (is_array($oneD imensionalArray )) {
$this->resultsObjec t->debugNotes(" In
getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsMysql, we expect the filter object '$filterName'
to return a row of data as an array, and it has.");
return $oneDimensional Array;
} else {
$this->resultsObjec t->addToErrorResu lts("In
getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsMysql, we expect the filter object '$filterName'
to return a row of data as an array, and it has not.");
}
} else {
$this->resultsObjec t->addToErrorResu lts("In
getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsMysql, we expected the format object '$className'
to return a row of data as an array, and it did not.");
}
} else {
$this->resultsObjec t->addToErrorResu lts("In the
getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsConnector MySql, we expected to be given a pointer
to data returned from the database during the last SELECT call.
Instead we got: $dsResultPointe r ");
}
}
Inside the data format class, I've got this:
/**
* 11-04-03 - it is important that the resource which points to the
returned dataset gets passed into this method
* by reference, not by copy, or else, in the outside code that is
calling this method, the pointer in that resource
* will never advance to the next resource row.
*/
function dsRowIntoArrayW ithStringIndex( &$dsResult) {
// 11-04-03 - this first lines test to see if anything came back
from the datastore
if (is_resource($d sResult)) {
$row = mysql_fetch_arr ay($dsResult, MYSQL_ASSOC);
$row = $this->stripslashesFr omEntryWithKeyI ndex($row);
return $row;
} else {
$this->resultsObjec t->addToErrorResu lts("In
dsRowIntoArrayW ithStringIndex( ), in the class McFormatResults MySql, we
expected the method to be handed a pointer to a database return
resource, but we were not.");
}
}
and I've also got this:
function stripslashesFro mEntryWithKeyIn dex($entry) {
if (is_array($entr y)) {
while (list($key, $val) = each($entry)) {
$entry[$key] = stripslashes($v al);
}
} else {
$this->resultsObjec t->addToErrorResu lts("In
stripslashesFro mEntryWithKeyIn dex(), in the class
McFormatResults MySql, we expected the method to be handed an array,
but it was not.");
}
return $entry;
}
These are the errors that get printed out on the 2nd and 3rd loop:
In stripslashesFro mEntryWithKeyIn dex(), in the class
McFormatResults MySql, we expected the method to be handed an array,
but it was not.
<hr> In getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsMysql, we expected the format object
'mcformatresult smysql' to return a row of data as an array, and it did
not.
<hr> In getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esults, we expected the data object
'mcgetdatastore resultsmysql' to return a row of data to us as an
array, but it has not.
<hr> In getRowAsArrayWi thStringIndex() , in the class McSelect, we
expected the data object 'mcgetdatastore results' to return a row of
data to us, but it has not.
<hr> In stripslashesFro mEntryWithKeyIn dex(), in the class
McFormatResults MySql, we expected the method to be handed an array,
but it was not.
<hr> In getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsMysql, we expected the format object
'mcformatresult smysql' to return a row of data as an array, and it did
not.
<hr> In getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esults, we expected the data object
'mcgetdatastore resultsmysql' to return a row of data to us as an
array, but it has not.
<hr> In getRowAsArrayWi thStringIndex() , in the class McSelect, we
expected the data object 'mcgetdatastore results' to return a row of
data to us, but it has not.
As I say, this was working perfectly for weeks (since November) but
now it is not. I anyone sees what mistake I made, I'd be grateful for
the feedback.
it stopped working. I'm not sure what I did. Nor can I make out why it
isn't working. I'm running a query that should return 3 items from the
database. I then get a count of the return, which correctly tells me
that I've got 3 items. I then go into a for loop which I expect to
loop 3 times and print out the 3 items. Here is where things get
strange: it loops 3 times and prints out the same item all 3 times.
More so, the 2nd and 3rd time it complains that it is not getting an
array (meaning it should have nothing to print, yet it prints. If
anyone can see the error I've made, I'd be damned grateful
inside a function called listAll, I've got this:
// 12-05-03 - I originally used the "GetAllOfTy pe" query, but now I
realize I only
// need ids, so instead we'll use the GetAllOfTypeJus tIds
$selectObject = & $controllerForA ll->getObject("McS elect");
$selectObject->setQueryObject ("GetAllOfTypeJ ustIds");
$selectObject->setInfoToBeSou ght($type);
$selectObject->getInfo();
$howMany = $selectObject->getCountOfRetu rn();
for ($i=0; $i < $howMany; $i++) {
$row = null;
$row = $selectObject->getRowAsArrayW ithStringIndex( );
if (is_array($row) ) {
extract($row);
$arrangementObj ect->setControlPane lCbId($cbId);
$controllerForA ll->getArrangement ($arrangement);
} else {
$r = $i + 1;
$resultsObject->addToErrorResu lts("In the function listAll(), we
expect to print out $howMany items, yet for some reason on attempt $r
we did not get an array back from the data as an array.");
}
}
Inside of the select object, I've got this:
/**
* 11-04-03 - wrapper of getter
* We take the resource that points to the returned dataset and feed
it into a method of $formatDatastor eResults.
* We are using the resource pointer to the returned dataset to fetch
the next row and return it with a string index
*/
function getRowAsArrayWi thStringIndex() {
$row = array();
if (is_resource($t his->dsResultPointe r)) {
$row = $this->getDataObjec t->getRowAsArrayW ithStringIndex( &$this->dsResultPointe r);
if (is_array($row) ) {
$className = get_class($this->getDataObject) ;
$this->resultsObjec t->debugNotes(" In
getRowAsArrayWi thStringIndex() , in the class McSelect, we expected the
data object $className to return a row of data to us (as an array),
and it has.");
return $row;
} else {
$className = get_class($this->getDataObject) ;
$this->resultsObjec t->addToErrorResu lts("In
getRowAsArrayWi thStringIndex() , in the class McSelect, we expected the
data object '$className' to return a row of data to us, but it has
not.");
}
} else {
$this->resultsObjec t->addToErrorResu lts("In
getRowAsArrayWi thStringIndex() , in the class McSelect, we looked for
the object's resource pointer to a database return, but the select
object didn't have one.");
}
}
Inside the getData object, I've got this:
function getRowAsArrayWi thStringIndex(& $dsResultPointe r) {
$array = $this->getDataObjec t->getRowAsArrayW ithStringIndex( &$dsResultPoint er);
$className = get_class($this->getDataObject) ;
if (is_array($arra y)) {
$this->resultsObjec t->debugNotes(" In
getRowAsArrayWi thStringIndex() , in the class McGetDatastoreR esults, we
expected the data object '$className' to return a row of data to us as
an array, and it has.");
return $array;
} else {
$this->resultsObjec t->addToErrorResu lts("In
getRowAsArrayWi thStringIndex() , in the class McGetDatastoreR esults, we
expected the data object '$className' to return a row of data to us as
an array, but it has not.");
}
}
Inside the get datastore connector object, I've got this:
/**
* 11-04-03 - obviously, this is just a wrapper for a method in the
queryObject
* We take the resource that points to the returned dataset and feed
it into a method of $formatDatastor eResults.
* We are using the resource pointer to the returned dataset to fetch
the next row and return it with a string index
*
* @param - $dsResultPointe r - this is a resource pointer, pointing to
the data returned from the last SELECT call
* to the datastore.
*
* returns array - 1 dimensional
*/
function getRowAsArrayWi thStringIndex(& $dsResultPointe r) {
if (is_resource($d sResultPointer) ) {
$oneDimensional Array =
$this->formatDatastor eResults->dsRowIntoArray WithStringIndex (&$dsResultPoin ter);
$className = get_class($this->formatDatastor eResults);
if (is_array($oneD imensionalArray )) {
$this->resultsObjec t->debugNotes(" In
getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsMysql, we expected the format object '$className'
to return a row of data as an array, and it did.");
$oneDimensional Array =
$this->filterDataObje ct->thisVisitorIsA llowedToViewThi sEntry($oneDime nsionalArray);
$filterName = get_class($this->filterDataObje ct);
if (is_array($oneD imensionalArray )) {
$this->resultsObjec t->debugNotes(" In
getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsMysql, we expect the filter object '$filterName'
to return a row of data as an array, and it has.");
return $oneDimensional Array;
} else {
$this->resultsObjec t->addToErrorResu lts("In
getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsMysql, we expect the filter object '$filterName'
to return a row of data as an array, and it has not.");
}
} else {
$this->resultsObjec t->addToErrorResu lts("In
getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsMysql, we expected the format object '$className'
to return a row of data as an array, and it did not.");
}
} else {
$this->resultsObjec t->addToErrorResu lts("In the
getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsConnector MySql, we expected to be given a pointer
to data returned from the database during the last SELECT call.
Instead we got: $dsResultPointe r ");
}
}
Inside the data format class, I've got this:
/**
* 11-04-03 - it is important that the resource which points to the
returned dataset gets passed into this method
* by reference, not by copy, or else, in the outside code that is
calling this method, the pointer in that resource
* will never advance to the next resource row.
*/
function dsRowIntoArrayW ithStringIndex( &$dsResult) {
// 11-04-03 - this first lines test to see if anything came back
from the datastore
if (is_resource($d sResult)) {
$row = mysql_fetch_arr ay($dsResult, MYSQL_ASSOC);
$row = $this->stripslashesFr omEntryWithKeyI ndex($row);
return $row;
} else {
$this->resultsObjec t->addToErrorResu lts("In
dsRowIntoArrayW ithStringIndex( ), in the class McFormatResults MySql, we
expected the method to be handed a pointer to a database return
resource, but we were not.");
}
}
and I've also got this:
function stripslashesFro mEntryWithKeyIn dex($entry) {
if (is_array($entr y)) {
while (list($key, $val) = each($entry)) {
$entry[$key] = stripslashes($v al);
}
} else {
$this->resultsObjec t->addToErrorResu lts("In
stripslashesFro mEntryWithKeyIn dex(), in the class
McFormatResults MySql, we expected the method to be handed an array,
but it was not.");
}
return $entry;
}
These are the errors that get printed out on the 2nd and 3rd loop:
In stripslashesFro mEntryWithKeyIn dex(), in the class
McFormatResults MySql, we expected the method to be handed an array,
but it was not.
<hr> In getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsMysql, we expected the format object
'mcformatresult smysql' to return a row of data as an array, and it did
not.
<hr> In getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esults, we expected the data object
'mcgetdatastore resultsmysql' to return a row of data to us as an
array, but it has not.
<hr> In getRowAsArrayWi thStringIndex() , in the class McSelect, we
expected the data object 'mcgetdatastore results' to return a row of
data to us, but it has not.
<hr> In stripslashesFro mEntryWithKeyIn dex(), in the class
McFormatResults MySql, we expected the method to be handed an array,
but it was not.
<hr> In getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esultsMysql, we expected the format object
'mcformatresult smysql' to return a row of data as an array, and it did
not.
<hr> In getRowAsArrayWi thStringIndex() , in the class
McGetDatastoreR esults, we expected the data object
'mcgetdatastore resultsmysql' to return a row of data to us as an
array, but it has not.
<hr> In getRowAsArrayWi thStringIndex() , in the class McSelect, we
expected the data object 'mcgetdatastore results' to return a row of
data to us, but it has not.
As I say, this was working perfectly for weeks (since November) but
now it is not. I anyone sees what mistake I made, I'd be grateful for
the feedback.
Comment