note 69791 added to function.mysql-fetch-assoc
| From: | q-tech at phreaker dot net | Date: | Thu, 21 Sep 2006 10:18:52 +0000 |
| Subject: | note 69791 added to function.mysql-fetch-assoc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-117373@lists.php.net to get a copy of this message | ||
In regards to Maviee's fetch function I suggest a more functional approach:
<?php
function msq($q)
{
global $dbqcount; //Count queries for the page;
$dbqcount++;
if (!$res=mysql_query ($q)) die (mysql_error());
$rr[0]=0; //$rr[0] countains number of the returned results
if (is_resource($res))
{
while ($rr[]=mysql_fetch_assoc($res)) $rr[0]++;
mysql_free_result($res);
}
return $rr;
}
?>
Also I would like to point out that mysql_fetch_assoc does associate array EXACTLY to the name of
the fields/functions you've recieved results for! E.g.:
<?php
$rez=msq("SELECT MAX(
ID) FROM table1"); // $rez will contain
assoc. variable named $rez[1]['MAX(ID)'], not $rez[1]['ID']
?>
----
Server IP: 66.163.161.117
Probable Submitter: 217.18.243.194
----
Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-assoc.php
Edit -- https://master.php.net/note/edit/69791
Del: integrated -- https://master.php.net/note/delete/69791/integrated
Del: useless -- https://master.php.net/note/delete/69791/useless
Del: bad code -- https://master.php.net/note/delete/69791/bad+code
Del: spam -- https://master.php.net/note/delete/69791/spam
Del: non-english -- https://master.php.net/note/delete/69791/non-english
Del: in docs -- https://master.php.net/note/delete/69791/in+docs
Del: other reasons-- https://master.php.net/note/delete/69791
Reject -- https://master.php.net/note/reject/69791
Search -- https://master.php.net/manage/user-notes.php