note 60667 added to function.mysql-fetch-assoc

From: Date: Fri, 13 Jan 2006 10:38:32 +0000
Subject: note 60667 added to function.mysql-fetch-assoc
Groups: php.notes 
Request: Send a blank email to php-notes+get-101694@lists.php.net to get a copy of this message
I'll show you a small function which creates a normal array out of a mysql_fetch_assoc foreach loop. First of all, I want to say, I have the philosphy that a function has exactly one return point. That's why I'm working with a return variable. Now here is the code: public function DBSelect($statement) { $ident = mysql_query($statement); $result = true; if ($ident == false || mysql_num_rows($ident) == 0) $result = false; // only create the array when everything went fine if ($result != false) { unset($result); // workaround to avoid a 2-dimensional array foreach(mysql_fetch_assoc($ident) as $key => $value) { $result[$key] = $value; } mysql_free_result($ident); } return $result; } ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-assoc.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60667 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60667&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60667&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60667&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60667&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60667&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60667&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60667&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60667&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101694) next »