Mike Peters <o0****************@THIShotmail.com> wrote in message news:<1d******************************@news.terane ws.com>...
mysql_data_seek lets you move the array pointer to the specified point.
Why not just use:
while ( $row = mysql_fetch_array($results)) {
// Do your stuff
}
Because that would mean using msyql specific commands in the main part
of my code. I've masked out all the mysql stuff. I've a selectObject
that all queries get run through. It might be getting data from mysql
or postgre or a file or an xml stream. The code doesn't know where the
data comes from. So my loop looks like this:
$selectObject->setQuery("GetAllWeblogEntries");
$selectObject->getData();
$howMany = $selectObject->getCount();
for ($i=0; $i < $howMany; $i) {
$row = $selectObject->getNextRow();
}
This was working perfectly till this week, when I made some changes
and busted it. I'm not sure what I did wrong. The getCount method
still works correctly and returns the correct number of items that
have been returned. But then in the for() loop, the getNextRow()
method only works the first time. After that it returns nothing. I'm
very confused by this - I'd think either the pointer would advance to
the next row, or it would stay stuck on the first row and return that
for how ever many times $howMany equals. But instead it works once and
then returns nothing. However, it remains a valid resource pointing to
a database return. I know this because inside of getNextRow the result
pointer gets tested every time with is_resource($results) and it never
tests false. So I'm confused about what is going on.
Today, in desperate attempt to get the code working again, I changed
things so that I could pass the loop index into getNextRow and feed it
to mysql_data_seek. But it still didn't work. This is what I'm
currently trying:
$selectObject->setQuery("GetAllWeblogEntries");
$selectObject->getData();
$howMany = $selectObject->getCount();
for ($i=0; $i < $howMany; $i) {
$row = $selectObject->getNextRow($i);
}
then, inside getNextRow(), I go:
if (is_resource($result)) {
$success = mysql_data_seek($result, $i);
if ($success) {
$resultsObject->debugNotes("Tested true");
} else {
$resultsObject->addToErrorResults("Tested false");
}
}
And it keeps testing false. I'm a little stunned by this. Why is
mysql_data_seek() failing if the resource is testing true in
is_resource()? I'm having a damned hard time figuring it out.
I also echo out the actual query to the screen and then run it through
phpMyAdmin so I can see what kind of return I should expect. All day
I've been running my tests on one query where I know I should be
getting back 3 entries. phpMyAdmin tells me so and the method
getCount() correctly comes back with 3. And, as I said, the first row
comes back fine. After that nothing works.
I'm passing the resource pointer by reference, so what happens inside
the object should effect what happens outside.