CodeIgniter Forums
I added new function in DB_result.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: I added new function in DB_result.php (/thread-12052.html)



I added new function in DB_result.php - El Forum - 10-03-2008

[eluser]Atas[/eluser]
I added this function in DB_result.php

Code:
function result_with_table_name() {
       $result = $this->result_id;
      
        $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];
            }
            $return[]=$new_row;
        }
        
        return $return;
    }

This function returns an array joining the table name and field name. This is very useful when we need to use "SQL JOIN" and some fields has the same name. Does codeigniter have already a similar function?