Advertisement

04.10.2008 at 08:18AM PDT, ID: 23312061
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

very very slow database query problems with php script

Asked by empirent in PHP Scripting Language, PHP and Databases, MySQL Server

Tags: ,

Each month, I run a script that adds up data from our clients' accounts and the volume they run through our system. In a certain table, for example, I have a client number that identifies the client and then selects their volumes from a separate table for processing.

Here is a sample of the code:

-> start by selecting a clientID the run through the table and add up all the numbers.

$sql_get_clientID = "SELECT clientID FROM EPI_ClientTotals$YYYYMM ORDER BY clientID ASC";
$result_get_clientID = mysql_query($sql_get_clientID ) or die ("Couldn't get record!");

while ($row_clientID = mysql_fetch_array($result_get_clientID)) {

      $clientID _INPUT = $row_clientID["clientID"];

$sql_get_loc_info = "SELECT * FROM FINANCIAL_HIST_REVENUE_$YYYYMM where (clientID = \"$clientID _INPUT\")";

$result_get_loc_info = mysql_query($sql_get_loc_info) or die ("Couldn't get record!");

$query1 = @mysql_query("select SUM(FINANCIAL_HIST_REVENUE_$YYYYMM.sales_trn) as sales_trn_A FROM FINANCIAL_HIST_REVENUE_$YYYYMM where (clientID= \"$clientID_INPUT\" && (TransType = '1'))")
or die(mysql_error());
$row1 = mysql_fetch_assoc($query1);

$VOL_TRANS_A = $row1['sales_trn_A'];


It goes on and on like this adding up about 20 - 25 different transaction types and amounts in a foreach loop on each clientID. But it takes about 5 minutes to add up 1 full record and then I do an Update table query to update the table with the right amounts. i.e. update table set VOL_TRANS_A = $VOL_TRANS_A, VOL_TRANS_B = $VOL_TRANS_B, etc. WHERE clientID = $clientID_INPUT...

The problem is, I have php programming experience, but I'm wondering why it takes FOREVER to run this query. For each 1000 clients, it takes at least a day. I've tried running on a faster server, but it just goes slow.

Any thoughts?

Should I move to an ASP.net solution and rewrite the code? (which I have no experience with, by the way)...

thanks!


Start Free Trial
[+][-]04.10.2008 at 08:31AM PDT, ID: 21325906

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, PHP and Databases, MySQL Server
Tags: php mysql, php mysql
Sign Up Now!
Solution Provided By: amilan
Participating Experts: 3
Solution Grade: A
 
 
[+][-]04.10.2008 at 10:29AM PDT, ID: 21327276

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628