note 42255 added to function.sqlite-fetch-array

From: Date: Sun, 09 May 2004 22:12:50 +0000
Subject: note 42255 added to function.sqlite-fetch-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-69393@lists.php.net to get a copy of this message
I noticed that if you use Joins in SQL queries, the field name is messed up with the dot! for example if you have this query: SELECT n.*, m.nickname FROM news AS n, members AS m WHERE n.memberID = m.id; now if you want to print_r the results returned using SQLITE_ASSOC type, the result array is like this : array ( [n.memberID] => 2 [n.title] => test title [m.nickname] => NeverMind [tablename.fieldname] => value ) and I think it looks horriable to use the variable ,for example, $news['m.nickname'] I just don't like it! so I've made a small function that will remove the table name (or its Alias) and will return the array after its index is cleaned <?php function CleanName($array) { foreach ($array as $key => $value) { //if you want to keep the old element with its key remove the following line unset($array[$key]); //now we clean the key from the dot and tablename (alise) and set the new element $key = substr($key, strpos($key, '.')+1); $array[$key] = $value; } return $array; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.sqlite-fetch-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42255 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42255&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42255&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69393) next »