Re: code help!
| From: | Hans H. Anderson | Date: | Tue, 05 Sep 2000 17:05:25 +0000 |
| Subject: | Re: code help! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-15331@lists.php.net to get a copy of this message | ||
>
> ya the info is in a database. How do I know when all the zipcodes have
> been sum'd? I mean if I loop through how does it know when its exausted
> all the zipcodes?
mysql sums them for you and returns the sum. However, I think
count() would be more efficient (the mysql docs seem to indicate it's
pretty fast)
select count(zips) as numzips from table where zips = 'zipcode'
will give you a result with the column 'numzips' that you can access in
the normal way (mysql_result(), for example, or mysql_fetch_row() or
mysql_fetch_array()).
> Additionally the above select (with the sum() function) works, however it
> takes a second to execute on a zipcode which only had about 100 entries
> (developement database server is small p166),
Make sure you have an index on any column that will appear in a where
clause. If you don't, it's going to be slow.
> I've got some which have 900 to 1000 entries would it be more efficent to
> do the summing in the php code rather than having the database do it?
No, the database should be faster for this task.
--
Hans Anderson -=-
me@hansanderson.com | PHP, SQL Databases, Flash 5 Animation
http://www.hansanderson.com | & Programming, Killer
Audio Production,
http://www.goofiness.com | Search Engines, Brewmeister.