note 69087 deleted from function.mysql-fetch-array by bjori
| From: | bjori@php.net | Date: | Wed, 23 Aug 2006 07:35:53 +0000 |
| Subject: | note 69087 deleted from function.mysql-fetch-array by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-116202@lists.php.net to get a copy of this message | ||
Note Submitter: JustinB at harvest dot org
----
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 . . .