Re: Array?
| From: | Joao Prado Maia | Date: | Fri, 06 Oct 2000 20:24:11 +0000 |
| Subject: | Re: Array? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-18969@lists.php.net to get a copy of this message | ||
On Fri, 6 Oct 2000, Matt McClanahan wrote:
> Perhaps, but it's also extremely inefficient. mysql_result isn't intended
> to be used in that manner. Besides, the end result will be only 5
> variables, $Project, $ProjType, $Company, $Event, and $EventType, set to
> the last values that they had in the SQL result.
>
> In the above code, you're grabbing a single cell from the result set
> multiple times ($rows * $fields times, actually). A much faster
> alternative would be to use mysql_fetch_row() or mysql_fetch_array(),
> which grabs data one row at a time.
>
> Also, if you want to pull out a variable per field for a row set, you
> could simply do
>
> while ($row = mysql_fetch_array($result))
> {
> extract($row);
> // Now you have $Project, $ProjType, $Company, $Event, and $EventType
> // But they will all be reassigned in the next iteration of the loop.
> }
Oh yeah, it is inefficient, but it came in handy sometimes when I needed
to do something with ODBC. The odbc_num_rows() function or similar was
returning -1, and other weird stuff were appearing on the screen. I used
the code I showed when debugging the database / scripts, and only after 2
hours of work I found one mention in some hidden place of the manual that
some ODBC drivers for PHP always returned -1 for number of rows.
Anyway, I'm not saying it's a good code to use, but it's sweet :)
I personally use mysql_fetch_object / pg_Fetch_Object for all my scripts
usually, so I understand what you are saying.
Joao
--
Joao Prado Maia
Web Developer
Kefta, Inc.
T: (415) 391-6881 ext 8008
F: (415) 391-7079