Modify an ADODB resultset before displaying with rs2html()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
techniq
Forum Newbie
Posts: 6
Joined: Sat May 18, 2002 12:15 pm
Location: US

Modify an ADODB resultset before displaying with rs2html()

Post 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
techniq
Forum Newbie
Posts: 6
Joined: Sat May 18, 2002 12:15 pm
Location: US

I found the solution...

Post 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
Post Reply