Jump to content

Recommended Posts

i have a MySQL query that loops multiple times, but not always the same amount of times. Each loops gets data from a specific sales campaign. The loop to query the data works fine

 
while($z<$customrows)
        {
         
$query = "SELECT
                vicidial_users.user,
                                vicidial_users.full_name,
                                vicidial_log.list_id,
                                COUNT(CASE WHEN (vicidial_log.status = 'SALE') THEN 1 ELSE null END) as sumcountSamnt,
                                COUNT(CASE WHEN (vicidial_log.status = 'SALE' AND custom_$customID[$z].up_amt <> '') THEN 1 ELSE null END) as sumcountupAmnt,
                                COUNT(CASE WHEN (vicidial_log.status = 'SALE' AND custom_$customID[$z].cc_num <> '') THEN 1 ELSE null END) as sumccverifiedcountAmnt,
                                COUNT(CASE WHEN (vicidial_log.status = 'SALE' AND custom_$customID[$z].bank_act <> '') THEN 1 ELSE null END) as sumbankverifiedcountAmnt,
                                SUM(CASE WHEN (vicidial_log.status = 'SALE' AND custom_$customID[$z].cc_num <> '') THEN custom_$customID[$z].s_amount ELSE null END) as sumccverifiedAmnt,
                                SUM(CASE WHEN (vicidial_log.status = 'SALE' AND custom_$customID[$z].bank_act <> '') THEN custom_$customID[$z].s_amount ELSE null END) as sumbankverifiedAmnt,
                                SUM(CASE WHEN (vicidial_log.status = 'SALE') THEN custom_$customID[$z].d_amt ELSE null END) as sumDamnt,
                                SUM(CASE WHEN (vicidial_log.status = 'SALE') THEN custom_$customID[$z].up_amt ELSE null END) as sumUpamnt,
                                SUM(CASE WHEN (vicidial_log.status = 'SALE') THEN custom_$customID[$z].md_amt ELSE null END) as sumMdamnt,
                                SUM(CASE WHEN (vicidial_log.status = 'SALE') THEN custom_$customID[$z].s_amount ELSE null END) as sumSamnt
                               
                        FROM
                                vicidial_log
                        INNER JOIN
                                vicidial_users
                        ON
                                (vicidial_log.user = vicidial_users.user)
                        INNER JOIN
                                custom_$customID[$z]
                        ON
                                (vicidial_log.lead_id = custom_$customID[$z].lead_id)
                        WHERE
                                call_date
                        BETWEEN
                                '$today 00:00:00'
                        AND
                                '$today 23:59:59'
                        AND
                            vicidial_log.user != 'VDAD'
                        AND
                            $customID[$z] != '39470562'
                        AND
                                vicidial_users.user_group != 'TX-Training'
                        GROUP BY
                                vicidial_log.user, vicidial_log.campaign_id
                       
                        ";
$stmnt = mysql_query($query);
                $stmntnumRows = mysql_num_rows($query);
                while($stmntResult = mysql_fetch_assoc($stmnt))
                {
                         $salescountResult[] = $stmntResult["sumcountSamnt"];
                         $upResult[] = $stmntResult["sumcountupAmnt"];
                         $countverifiedccResult[] = $stmntResult["sumccverifiedcountAmnt"];
                         $amountverifiedccResult[] = $stmntResult["sumccverifiedAmnt"];
                         $countverifiedbankResult[] = $stmntResult["sumbankverifiedcountAmnt"];
                         $amountverifiedbankResult[] = $stmntResult["sumbankverifiedAmnt"];
                         $damounttotalResult[] = $stmntResult["sumDamnt"];
                                         
                }
               
        $z++;
        }
 

i can loop through and output the data of each iteration, no problem. I can sum the complete data values in an array for example there are 29 users and i can sum all the sales for all the user, but i cant seem to sum the total sales per user across all campaigns
this is how i iterate the output

for($i = 0; $i  < count($customID); ++$i)
        {
       
        echo "hi "/*.$nameResult[$i]. " - "*/.$upResult[$i]./*;" - ".$salescountResult[$i].*/"<br>";
       
        }

im sure its something simple, but im just not seeing it. Thanks for your help

Link to comment
https://forums.phpfreaks.com/topic/278642-summing-array-value/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.