note 60924 added to function.mysql-fetch-assoc

From: Date: Fri, 20 Jan 2006 07:45:18 +0000
Subject: note 60924 added to function.mysql-fetch-assoc
Groups: php.notes 
Request: Send a blank email to php-notes+get-102149@lists.php.net to get a copy of this message
I'm just getting back to php/sql and I was finding I writing too many if elses when i decided to make a function that returned an array of values i needed so i could just loop through it or peck and hunt if i wanted. ################################################# # function returns an array of associative values function doSQL ($q) { // query the database $result = mysql_query($q); if(!$result) { sqlError(); } else { // take the table info and return it as an array while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $sql_array = array_map(null, $row); return $sql_array; } } } $myArray = doSQL('SELECT * FROM some_table WHERE some_value = some_number); print_r($myArray); ---- Server IP: 64.71.164.2 Probable Submitter: 69.227.158.235 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-assoc.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60924 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60924&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60924&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60924&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60924&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60924&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60924&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60924&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60924&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102149) next »