PX : code

SetMySQLResults Func by Hans Anderson
Download this code


<?php
function setmysqlresults($resultpointer,$row 0) {
 
$i=0;
 
$n=mysql_num_fields($resultpointer);
 while(
$i<$n) {
   
$fieldname mysql_field_name($resultpointer,$i);
   
$fieldresult mysql_result($resultpointer,$row,$fieldname);
   
$hash[$fieldname] = $fieldresult;
 
$i++;
}
 return 
$hash;
// end setmysqlresults()

/* 

usage:

$r = mysql_query("select Column1, Column2, Column3 from Table");
$i=0;
while(mysql_fetch_row($r)) {
 $rs = setmysqlresults($r,$i);
 print "$rs[Column1], $rs[Column2], $rs[Column3]\n";
 $i++;
}

Using this function, you won't need to go through the lengthy assignment
of mysql_result() to variables.

To test for validity, use is_array(). If this function fails, it will
return a simple value.  If it succeeds, it will be an associative array. For
more information on associative arrays, see the PHP3 manual for array().

*/

?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.