close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Calculated fields in recordset?

Thread began 6/29/2012 5:41 am by gary.brett434358 | Last modified 7/05/2012 12:38 pm by Jason Byrnes | 4312 views | 15 replies |

gary.brett434358

Calculated fields in recordset?

Good morning, not specifically a DA issue but wondered if anyone could help? DA creates my results tables perfectly, 2 columns contain numbers & currency, is there anyway using php to calculate these fields, such as adding sum values to table footer?

I did think to do this in mysql using SUM (sales_price) AS Total but the recordset is dynamic and can change as I filter the records ie;

Staff1 10 £250
Staff2 15 £300
Staff2 5 £100
Staff3 20 £400
Total 50 £1050

If I then filter it to 'staff3' I need it to update as such;

Staff3 20 £400
Total 20 £400

Kind regards

Gary

Sign in to reply to this post

Jason ByrnesWebAssist

using SUM in the SQL should work even if the recordset is dynamic.


SELECT SUM(sales_price) AS Total FROM tableName WHERE columnName = "staff 3"

would return the result you are looking for.

Sign in to reply to this post

gary.brett434358

Hi Jason thanks for your input, the filtering is not done in mysql but via master/detail links, using code below works on master recordset but not on detail pages as its simply display the total recordset sums.

Select
tblcontacts.ContactFullName As Name,
Count(tblcases.CaseID)As Cases,
Sum(tblcases.CaseCommission) As Commission
From
tblcontacts Inner Join
tblcases On tblcontacts.ContactID =
tblcases.ContactAssignedTo
Group By
tblcontacts.ContactFullName

UNION ALL

Select
'GRAND-TOTAL',
Count(tblcases.CaseID),
Sum(tblcases.CaseCommission)
From
tblcontacts Inner Join
tblcases On tblcontacts.ContactID =
tblcases.ContactAssignedTo



Not sure how I would do this now, I had started to look at php methods but have no real idea if php can even do calcs?

Sign in to reply to this post

Jason ByrnesWebAssist

the master page passes an ID to the detail page using a URL variable in the link.

on the detail page, you use the URL variable to filter the recordset using a where clause.

your recordset is not working on the detail page, because you are missing the where clause that will limit the results returned to only include those related to the URL variable.

Sign in to reply to this post

gary.brett434358

Originally Said By: Jason Byrnes
  your recordset is not working on the detail page, because you are missing the where clause that will limit the results returned to only include those related to the URL variable.  



Hi Jason, that's where I was going wrong I think, the where clause was above the union query so it filtered the details correctly but not the sums. Creating a 2nd identical where under union works in phpmyadmin but it seems I cant reuse parameters in DW?

If I create an identical parameter and use that in 2nd where it errors telling me it cant find field!

Code below works

Select
ghl_portal.tblcontacts.ContactFullName As Name,
Count(ghl_portal.tblcases.CaseID)As Cases,
Sum(ghl_portal.tblcases.CaseCommission) As Commission
From
ghl_portal.tblcontacts Inner Join
ghl_portal.tblcases On tblcontacts.ContactID =
ghl_portal.tblcases.ContactAssignedTo
WHERE ghl_portal.tblcontacts.ContactFullName = 'Barry'
Group By
ghl_portal.tblcontacts.ContactFullName

UNION ALL

Select
'GRAND-TOTAL',
Count(tblcases.CaseID),
Sum(tblcases.CaseCommission)
From
ghl_portal.tblcontacts Inner Join
ghl_portal.tblcases On ghl_portal.tblcontacts.ContactID =
ghl_portal.tblcases.ContactAssignedTo

WHERE ghl_portal.tblcontacts.ContactFullName = 'Barry'



But using DW Parameter twice doesn't, do you know if that's normal?

Sign in to reply to this post

Jason ByrnesWebAssist

yes, you cant use the same parameter twice, you need to create a second parameter with the same settings but unique name.

Sign in to reply to this post

gary.brett434358

Originally Said By: Jason Byrnes
  yes, you cant use the same parameter twice, you need to create a second parameter with the same settings but unique name.  



Hmmm, that's what is troubling me so much, I have tried countless times to do that but it returns "MySQL Error 1054: Unknown column in 'tblreferral.RefferalID' on WHERE clause" even after ensuring both param are named differently, sql code is below

mysql_select_db($database_ghl_portal, $ghl_portal);
$query_rsDetail = sprintf("SELECT tblreferral.RefferalID, tblreferral.ReferralName, Count(tblcases.CaseID) As Cases, tblcasestatus.CaseStatusName

FROM tblcases Inner Join tblcontacts On tblcontacts.ContactID = tblcases.ContactID Inner Join tblreferral On tblreferral.RefferalID =
tblcontacts.ContactReferrelSource Inner Join tblcasestatus On tblcasestatus.CaseStatusID = tblcases.CaseStatusName

WHERE tblreferral.RefferalID=%s GROUP BY tblreferral.RefferalID, tblcasestatus.CaseStatusName

UNION All

SELECT '', 'GRAND-TOTAL', Count(tblcases.CaseID),''
FROM tblcontacts Inner Join tblcases On tblcontacts.ContactID = tblcases.ContactAssignedTo
WHERE tblreferral.RefferalID=%s",
GetSQLValueString($ParamReferralID_rsDetail, "int"),GetSQLValueString($ParamReferralID2_rsDetail, "int"));



Also tried removing the Parameter to use WHERE tblreferral.RefferalID=$_GET['ReferralID'] with no success.

Sign in to reply to this post

Jason ByrnesWebAssist

the where clause is using the table tblreferral, this table is not included as part of the FROM or inner join clause.


you cant refer to a table in the where clause that is not used in the from or inner join clause of the query

the From and Inner Join portion of the query tells the database what tables you are looking at the data for.

Sign in to reply to this post

gary.brett434358

OK, when I add the where field to the select on 2nd query it allows the page to run but returns 0 as result, could this be due to the master page not sending a variable named Param2? I cant imagine I need to create 2 variables & parameters for each master/detail?

Can I use variables instead of parameters in DW do you know? When I try this in phpmyadmin it runs fine, something like WHERE tblreferral.RefferalID=$_GET['ReferralID']

Thanks Jason..

Sign in to reply to this post

Jason ByrnesWebAssist

make sure the run time value of both parameters is
$_GET['ReferralID']

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...