Page 1 of 1

Modify an ADODB resultset before displaying with rs2html()

Posted: Fri Oct 04, 2002 8:11 pm
by techniq
OK, I'm doing something a little different now. I'm taking the ADODBrecordset and creating an array from it with the code below:

Code: Select all

$dbconn->Connect($server, $user, $pass, $db);
$sSQL = 'select field1, field2 from table1';
$rs = $dbconn->Execute($sSQL);
$rs_array = $rs->GetArray();
Now $rs_array is a standard array. Can someone advise me on how I would change some values in that array?

[...previous msg...]
I'm using ADODB to query data from a MSSQL db and then using the ADODB function rs2html() to display the recordset in html format. I would like to change some value in the recordset before displaying it with rs2html(). Not sure what function(s) to use...maybe array_walk()?

Example:

Code: Select all

$dbconn->Connect($server, $user, $pass, $db);
$sSQL = 'select field1, field2 from table1';
$rs = $dbconn->Execute($sSQL);
//some code to modify values in the recordset
rs2html($rs, 'border=5', array(field1, field2));
Any help would be appreciated.

Thanks

I found the solution...

Posted: Wed Oct 09, 2002 8:05 am
by techniq
If anyone is trying to do this...the complete code would step you through obtaining the ADODBrescordset via SQL query, then move the ADODBrecordset to an array with the GetArray() func., then loop through the array to identify and change the value(s) you wish.

Code: Select all

<?php

/*
 ADODB syntax to create the db connection,
 create the select statement, and execute the query
*/

$dbconn->Connect($server, $user, $pass, $db); 
$sSQL = 'select field1, field2 from table1'; 
$rs = $dbconn->Execute($sSQL); 

//move the ADODBrecordset to an array.
$rs_array = $rs->GetArray();
$x = (count($rs_array) - 1);

/* 
 Loop through the first level of a 2-D array to change
 the 2nd element in the 2nd level.  If this value in the 
 array is 1, 2, or 3 change it to LOW, MEDIUM, or HIGH
 respectively.
*/

for ($i = 0; $i <= $x; $i++) {
	switch($rs_arrayї$i]ї0]) {
		case 3:
			$rs_arrayї$i]ї0] = "HIGH";
			break;			
		case 2:
			$rs_arrayї$i]ї0] = "MEDIUM";
			break;
		case 1:
			$rs_arrayї$i]ї0] = "LOW";
			break;
		}
}

?>
If anyone finds flaw in this please let me know. 8O