Reply to Re: retrieve single field from database without while loop

Your name:

Reply:


Posted by Matthew Weier O'Phinney on 10/04/45 11:08

* ross@aztechost.com <ross@aztechost.com>:
> 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@garden.org | http://vermontbotanical.org

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация