Re: retrieve single field from database without while loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* ross@xxxxxxxxxxxxx <ross@xxxxxxxxxxxxx>:
> Is there a way to retrieve and display a single value (customer number) from 
> a database and display it without using
>
> while ($row = mysql_fetch_array) ($result)){
>
>
> I have a value I know the query will only ever return a single value. I want 
> to get it from the database and convert it to a variable so I can use it on 
> my php page.

Use a DB abstraction layer. PEAR::DB and PEAR::MDB2 both have a getOne()
method that will grab the value from the first column of the first row
in the resultset:

    $result = $db->getOne($sql);

Yes, it's more overhead, but it makes things like this so trivial that
you have to ask if your time or your processor time is more important.
(And, frankly, on most machines these days won't even notice the
performance hit of loading one of these libraries.)

ADODB gets good reviews as well, and I'm pretty sure they have a similar
method.

-- 
Matthew Weier O'Phinney           | WEBSITES:
Webmaster and IT Specialist       | http://www.garden.org
National Gardening Association    | http://www.kidsgardening.com
802-863-5251 x156                 | http://nationalgardenmonth.org
mailto:matthew@xxxxxxxxxx         | http://vermontbotanical.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux