[thelist] Recordset Conundrum

RUST Randal RRust at COVANSYS.com
Thu Jan 23 08:14:26 CST 2003


I am using ADOdb with a MySQL db to create some back-end functionality.
My query script looks like this:

//run the query
$sql="select * from builders where builder_id=76";
$rs=$conn->Execute($sql);
//count the number of records returned
$recordcount=$rs->RecordCount();

Then I am trying to pull all of the values into an array:

echo $recordcount . " record" . "<br />";

if($rs){
	$cols=$rs->FetchRow($cols);
	while($cols){
		for($i=0; $i<$cols; $i++){
			//print each value
			echo $cols[$i] . "<br />"; }
		}
	}

What is happening is that the loop doesn't stop with the last column.
It just keeps running, even though it has reached the end of the values.
So once the script goes past column 21, I get a message...

Notice: Undefined offset: 21 in
c:\inetpub\wwwroot\adodbtest\arrayTest.php on line 36

And this goes on until I stop the page from executing.

I tried to use foreach on the array, but that did something weird too.
It looped over the array twice, and printed each value to the screen
twice.  Then I tried doing a simple count() on the array, and that
returned 42, but there are only 21 columns.  I am extremely confused by
all of this, but don't see any errors in the SQL.

----------
Randal Rust
Covansys Corp.
Columbus, OH



More information about the thelist mailing list