Welcome Guest, Not a member yet? Register   Sign In
Best Practice for Processing dbase Data
#1

[eluser]Fielder[/eluser]
Of these 2 ways, which in your opinion is better?

1. Use several sql statements to pull down data from the database, each statement running a slightly different query and letting SQL run the simple calculations and such? For instance
Code:
SELECT SUM(tot) AS n FROM table WHERE active = 1
Code:
SELECT * FROM table WHERE active = 1 GROUP BY 'title'
Code:
SELECT * FROM table WHERE active = 1 AND type = 1
...

2. Use 1 sql statement to pull down all the data, and create a helper or library with various functions with foreach loops to manipulate the returned results and get what I want?
Code:
function getTotal($array)
{
$total = 0;
foreach($array as $row)
{
if ($row['active'] == 1 $total++;
}
...
return $total;
}
Code:
function countType($array)
{
count($array);
return $count;
}

I suspect pulling everything down in 1 query and making my own functions is better because it is only one request to the mySQL server.


Messages In This Thread
Best Practice for Processing dbase Data - by El Forum - 09-12-2009, 06:10 PM
Best Practice for Processing dbase Data - by El Forum - 09-12-2009, 08:16 PM



Theme © iAndrew 2016 - Forum software by © MyBB