note 69087 added to function.mysql-fetch-array
| From: | JustinB at harvest dot org | Date: | Tue, 22 Aug 2006 17:22:57 +0000 |
| Subject: | note 69087 added to function.mysql-fetch-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116177@lists.php.net to get a copy of this message | ||
In response to both Solutions-at-lanetech and Adam:
First of all, Solutions isn't looking for the number of rows--he's looking for the number
of fields (columns) in a given result. While mysql_num_rows won't help him directly, there is
another way.
Unless you specifically need the data for other reasons (which I obviously don't know from your
post), I believe that using mysql_num_fields would be much faster, as you don't need to
actually return the result set or need to run that loop. Example:
<?php
// We'll just make do a query here, assuming that we're already connected to the DB
$query = 'SELECT * FROM
table WHERE id > 6465498 LIMIT 1000';
$result = mysql_query($query);
// If we just want the number of fields . . .
$fields = mysql_num_fields($result);
// Or, if--like in your example--we're looking for the total number for all rows (I don't
know why, but anyways . . .)
$fields = mysql_num_fields($result) * mysql_num_rows($result);
// I suppose that you could also make MySQL do the work:
$query = 'SELECT COUNT(*) FROM table LIMIT 1';
$result = mysql_query($query);
list($fields) = mysql_fetch_row($result);
?>
I hope that gives you some ideas . . .
----
Server IP: 216.194.113.175
Probable Submitter: 72.34.75.194
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php
Edit -- https://master.php.net/note/edit/69087
Del: integrated -- https://master.php.net/note/delete/69087/integrated
Del: useless -- https://master.php.net/note/delete/69087/useless
Del: bad code -- https://master.php.net/note/delete/69087/bad+code
Del: spam -- https://master.php.net/note/delete/69087/spam
Del: non-english -- https://master.php.net/note/delete/69087/non-english
Del: in docs -- https://master.php.net/note/delete/69087/in+docs
Del: other reasons-- https://master.php.net/note/delete/69087
Reject -- https://master.php.net/note/reject/69087
Search -- https://master.php.net/manage/user-notes.php