slrobinson1983;10971564 wrote:perfect. thats the part of the code i was trying to figure out. thanks!
Yes, that's the part you left out, so, it was fairly easy to tell 😃
Now, this is the point where we'd have to discuss PHP vs. SQL, because, as Dagon points out, there is an alternative, and that is to let the RDBMS handle some of these calculations. It's a big can of worms ... for example ... if you're learning to program in PHP, you should probably do you processing in PHP until such time as you're reading to learn SQL.
OTOH, there's a school of thought that would say, they go so closely together that you might as well learn SQL while you're learning PHP.
And then there's the question of good design: is it better to let PHP handle this, or the database? As I mention, it's a fairly small calculation of values that have already been pulled from the database. However, there are questions of performance, etc. If, for example, the PHP/Webserver was highly trafficked and the SQL server was on a separate machine that had plenty of capability, with a fast link to the web server, it might well be more efficient to let the database do the work.
Probably we could argue about this back and forth a good little while; the only real winner would be whoever could produce an adequately documented benchmark of this exact coding situation. It's probably not worth fretting about.
However, just because you picked "my" solution (hee hee, it's really anybody's solution ... plain as the nose on an experienced PHP coder's face), please don't think it's the only way to do it. People who understand SQL better than I do know that it's got a lot of processing power all wrapped up in itself 🙂
And hey, Dagon ... I'm working hard on SQL now 😃