On Tue, Jun 11, 2002 at 05:49:53PM +0000, A Taylor wrote:
> 'SELECT prop_rank FROM main ORDER BY prop_rank DESC'
>
> This returns many records but all i am interested in is the highest rank
> hence the 'ORDER BY prop_rank DESC'.
> I then retreive the highest rank like so:
>
> $rank = $sth1->fetchrow_array();
>
> Now, my question is this: is this the right way to retreive just 1 record,
> using fetchrow_array(); ??? or is there a more acceptable way. This does
> work, its just the 'array()' part is making me a little uneasy.
It's not clear what you mean by "record" here. It's typically synonymous
with "row", as in "fetchrow". Using a fetch method is the only way to
retrieve a record, so this is appropriate.
If, however, by record you mean "column" or "field", then it depends.
fetchrow_array() is probably the easiest, as it does not require
dereferencing. However, I'd use it like this:
($rank) = $sth->fetchrow_array();
Otherwise you're evaluating fetchrow_array() in scalar context, which may
not return what you expect in certain instances.
Also, if all you want is a single row, you should place a limit in your SQL
query:
SELECT prop_rank FROM main ORDER BY prop_rank DESC LIMIT 1
Don't make the database do more work than is necessary.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]