NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Math using MySQL or PHP

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Reply
 
LinkBack Thread Tools
Old 06-16-2009, 03:35 PM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Nov 2003
Location: Ontario, Canada
Posts: 127
eagle12 will become famous soon enougheagle12 will become famous soon enough
 



Math using MySQL or PHP


I was wondering if anyone knows is it better to perform math functions in PHP or using SQL? Please include reasons.
eagle12 is offline   Reply With Quote
Old 06-16-2009, 06:08 PM   #2 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
Inline SQL math operations are very speedy.

Depends if you're doing math directly related to the database or if you're compiling the information first and then doing math.
mholt is offline   Reply With Quote
Old 06-17-2009, 07:48 PM   #3 (permalink)
Account Suspended
Join Date: May 2007
Posts: 163
AdamWestdomains is a jewel in the roughAdamWestdomains is a jewel in the roughAdamWestdomains is a jewel in the rough
 



This is a good question and it would depend on a few considerations,
For most general use, the times would be negligible. SQL code would be faster when math operations have to be done repeatedly to large datasets, and for processing data and adding it back into the database. Part of this involves the fact that large datasets dont need to be transferred to the application/application memory. MySQL i optimized to process data on the db like this, other db's have procedures, etc.
????: NamePros.com http://www.namepros.com/programming/590430-math-using-mysql-or-php.html
Operations that involve storing the results for further processing, and that need to be really dynamic would be best in PHP code, things such as integrals, fatorials, amortization tables etc.
The caveat to SQL code is that its sometimes more complex than just using PHP, and unless you're beyond needing to process tens of thousands of rows, you probably wont see any speed gains.
+1 for PHP
AdamWestdomains is offline   Reply With Quote
Old 06-18-2009, 05:52 AM THREAD STARTER               #4 (permalink)
NamePros Member
Join Date: Nov 2003
Location: Ontario, Canada
Posts: 127
eagle12 will become famous soon enougheagle12 will become famous soon enough
 



Thanks for the responses. Here is the SQL I am working with:

Code:
select country.name, IFNULL(unverified,0) as unverified, IFNULL(verified,0) as verified, IFNULL(format(verified/(IFNULL(unverified,0)+verified)*100,2),'N/A') as average, IFNULL(verified + IFNULL(unverified,0),'N/A') as total from country left join  
(select count(*) as verified,country.countryID from school 
left join city using(cityID)
left join province using(provinceID)
left join country using(countryID)
where status = 1
group by country.name
order by country.name) as t1 using(countryID)
left join (select count(*) as unverified,country.countryID from school 
left join city using(cityID)
left join province using(provinceID)
left join country using(countryID)
where status = 0
group by country.name
order by country.name) as t2 using(countryID)
eagle12 is offline   Reply With Quote
Old 06-18-2009, 01:17 PM   #5 (permalink)
Account Closed
Join Date: Dec 2008
Location: Boston, Ma
Posts: 650
CrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to all
 



Marrow Donor Program Animal Rescue Autism Autism
I wouldn't run math in sql, it is speedy, but it taxes your resources as well.
CrackFeed.Com is offline   Reply With Quote
Old 06-18-2009, 01:35 PM   #6 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,558
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
IMO the performance hit will be the multiple joins. I hope you have good indexes.
Perhaps the whole statement could be optimized.
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is offline   Reply With Quote
Old 06-18-2009, 02:42 PM   #7 (permalink)
Account Closed
Join Date: Dec 2008
Location: Boston, Ma
Posts: 650
CrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to all
 



Marrow Donor Program Animal Rescue Autism Autism
I would try to combine tables if possible so you don't have to use joins. I try to avoid them at all costs.
CrackFeed.Com is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
HOWTO: Install the Apache Web Server, Perl, PHP, and MySQL on Windows deadserious Webmaster Tutorials 96 05-27-2007 02:24 PM
Great Scripts for Sale With Resale Rights! Zeeble Scripts For Sale 20 01-04-2006 02:39 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 09:04 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger