note 83754 modified in function.mysql-fetch-field by danbrown

From: Date: Sat, 20 Jun 2009 02:13:26 +0000
Subject: note 83754 modified in function.mysql-fetch-field by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157153@lists.php.net to get a copy of this message
A little function to help coders to distinct the tablename from a multiselect query where some fields has the same name in differents tables. <?php public function sql($sql) { $T_Return=array(); $result=@mysql_query($sql); $i=0; while ($i < mysql_num_fields($result)) { $fields[]=mysql_fetch_field($result, $i); $i++; } while ($row=mysql_fetch_row($result)) { $new_row=array(); for($i=0;$i<count($row); $i++) { $new_row[ $fields[$i]->table][$fields[$i]->name]=$row[$i]; } $T_Return[]=$new_row; } return $T_Return; } ?> --was-- A little function to help coders to distinct the tablename from a multiselect query where some fields has the same name in differents tables. public function sql($sql) { $T_Return=array(); $result=@mysql_query($sql); $i=0; while ($i < mysql_num_fields($result)) { $fields[]=mysql_fetch_field($result, $i); $i++; } while ($row=mysql_fetch_row($result)) { $new_row=array(); for($i=0;$i<count($row); $i++) { $new_row[ $fields[$i]->table][$fields[$i]->name]=$row[$i]; } $T_Return[]=$new_row; } return $T_Return; } http://php.net/manual/en/function.mysql-fetch-field.php

« previous php.notes (#157153) next »