converting a Recorset into an XML string

From: Date: Sat, 25 Jan 2003 22:35:36 +0000
Subject: converting a Recorset into an XML string
Groups: php.general 
Request: Send a blank email to php-general+get-133137@lists.php.net to get a copy of this message
Hello everybody, I make a function that lets you convert a recordset obtained via mysql_query() into an XML string: maybe could be helpfull to yours this is the function it have 3 parameters: $rs is the recordset you want to convert $padre is the name for the parent node that will contain every record on the recordset $hijo is the name for the child node that will contain a single record in the recordset function rs2xml($rs,$padre,$hijo){ $num_campos=mysql_num_fields($rs); $num_filas=mysql_num_rows($rs); if($padre!="-1") $xml="<$padre>\n"; else $xml=""; $cont1=0; while($cont1<$num_filas){ $fila=mysql_fetch_array($rs); $xml.="<$hijo>\n"; $cont=0; while($cont<$num_campos){ $nombre_campo=mysql_field_name($rs,$cont); $valor_campo=$fila[$cont]; $xml.="<".$nombre_campo.">".$valor_campo."</".$nombre_campo.">\n"; $cont++; } $xml.="</$hijo>\n"; $cont1++; } if($padre!="-1") $xml.="</$padre>\n"; return $xml; } I hope this will be helpful for you OCTAVIO HERRERA

« previous php.general (#133137) next »