phpLens
 home  products examples manual  faq support forum  contact news  login store

Forums: phplens   adodb
Forums:   ADOdb Help & Dev:   Replies 
New ReplySearch
Topic: recordset iretator bug/problem
author: jonas   created: 17-12-2003 03:28:01 PM
if (!$rs = $con->Execute('SELECT * FROM ArticleSection WHERE parentId='.$sectionId))
{
return 'inga underkategorier';
}

$string = '';
foreach ($rs as $section)
{
$string .= '<a href="article.php?sectionid='.$rs->fields['sectionId'].'">'.$rs->fields['name'].'</a> :: ';
}

that doesnt work for the first record, it will get skipped.
Topic: Re:recordset iretator bug/problem
author: John Lim   created: 18-12-2003 06:02:21 AM
Hi Jonas

Tested on php5 beta 2. The problem is that the iterator next() is called not at the end of the loop, but at the beginning of the loop. So $section will contain the right data, but $rs->fields will contain the next record as next() is called prematurely by php5.

eg.

foreach($rs as $val) {
echo $val;
}

should be translated to

while ($iterator->hasMore()) {
$val = $iterator->current();
echo $val;
$iterator->next();
}

when it actually outputs the incorrect:

while ($iterator->hasMore()) {
$val = $iterator->current();
$iterator->next();
echo $val;
}

You can see this behaviour when you modify the adodb-iterator.inc.php file to show debug output:

class ADODB_Iterator implements Iterator {

:
:

function current()
{
echo "CURRENT ";
return $this->rs->fields;
}
function next()
{
echo "NEXT ";
$this->rs->MoveNext();
}


I hope this is clear. In conclusion, this is a bug in php5. Perhaps you could submit a bug report to http://bugs.php.net/ and post the bug url here?
Topic: Re:recordset iretator bug/problem
author: verifier   created: 19-12-2003 03:45:58 AM
done.
Topic: Re:recordset iretator bug/problem
author: jonas   created: 19-12-2003 03:50:00 AM
I borrowed the code from your example in the bugreport.
http://bugs.php.net/bug.php?id=26663
Topic: Re:recordset iretator bug/problem
author: jonas   created: 19-12-2003 05:12:18 AM
Thanks for opening bug reports on already solved problems :-)
Page 1
New ReplySearch

View Source

email: contact#phplens.com (change # to @)     telephone (malaysia): 60-3-7947 2888     fax (malaysia): 60-3-7947 2800