Forums

SUM or COUNT and How!

MORAN 26 Oct, 2010
Hi Bob and all,
This is probably simplicity itself but being something of a scripting moron I am getting more and more confused.

I have a table with numerous records all containing, among other data, 6 fields showing a mark out of 10 (numerals) for various aspects of prowess in a certain job. For example Excellence, Originality, Inspiration etc ...each having a number between 1 and 10 given by a panelist/adjudicator.

Using Connectivity, I want to display the total of those 6 individual marks. This is in Joomla. Everything is showing up great except that, not being a scripter of much worth, the more I try to hack in some form of php/mysql syntax to get a total of those six marks out of ten, I'm screwing more things up than I am fixing.

Thanks to anyone who can help
GreyHead 27 Oct, 2010
Hi Moran,

To make the code useful, what are the column names that hold the scores?

Bob
MORAN 27 Oct, 2010
Thanks for getting back Bob. Table/form consists of the following:
id
date
panelist_firstname
panelist_lastname
artist_firstname
artist_lastname
discipline (dropdown select box)
*excellence
*originality
*influence
*insight
*awardworthy
comments
Hii spam block question
Submit and Reset

(asterisks indicate the boxes for scores)

Thanks for your help on this
John
MORAN 30 Oct, 2010
Hi Bob and All,

Been screwing around all weekend. Plainly not my forte. Checked as many forums as I could and am still obviously as pathetic at doing this as I always was. The nearest I've got is a return of zero from the following code (see below). Tried it in the header, footer and here in the body. See return in the second graphic. This is not pulled from a Chronoform. It's a regular old php form/mysql as per the data fields before and some of the data is already in there. I'd appreciate someone telling me what a wan**er I am by telling me where I'm going wrong. And apologies if I'm posting this wrong.

Hope someone can help
John
GreyHead 31 Oct, 2010
Hi John,

The problem with the array_sum you used was that the array is all text strings not numbers so when you add them up you don't get a meaningful total.

In the ChronoConnectivity Body box add this
<?php
$score_array = ('excellence', 'originality', 'influence', 'insight', 'awardworthy');
$total = 0;
foreach ( $award_array as $v ) {
  $total += $MyRow->$v;
}
?>
<tr>
. . .
<td>Total score is : <?php echo $total; ?></td>
. . . 

Bob
MORAN 31 Oct, 2010
Thanks for responding so quickly Bob. Unfortunately I get this message:


Parse error: syntax error, unexpected ',' in /awards/components/com_chronoconnectivity/libraries/connection.php(303) : eval()'d code on line 43

I tried it where you said, in the body, then in the header and the footer. No joy. Any thoughts?
John
GreyHead 31 Oct, 2010
Hi John,

Ther error is on Line 43 of the code in the Body box. Please take a look for anything out of place. If you don't see it then please copy and paste the whole boxfull of code here.

Bob
MORAN 01 Nov, 2010
Here we go. Line 43 is the start of the array, after I pasted it into Dreamweaver. I can't find any stray commas here. Thanks again.
<tr>
    <td>Score for Excellence</td>
    <td>{excellence}</td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Score for Originality</td>
    <td>{originality}</td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Score for Influence</td>
    <td>{influence}</td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Score for Insight</td>
    <td>{insight}</td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Score for Award Worthiness</td>
    <td>{awardworthy}</td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
<?php
$score_array = ('excellence', 'originality', 'influence', 'insight', 'awardworthy');
$total = 0;
foreach ( $score_array as $v ) {
  $total += $MyRow->$v;
}
?>
    <td>Total Scores</td>
    <td><?php echo $total;?></td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>

  </tr>
  <tr>

    <td colspan="2">Panelist's Comments:  {comments}</td>
  </tr>
GreyHead 01 Nov, 2010
Hi John,

Apologies, my blooper, missed the array before the (.
$score_array = array('excellence', 'originality', 'influence', 'insight', 'awardworthy');


Bob
MORAN 01 Nov, 2010
Cheers Bob. Brilliant. Thanks a million. The barman has your beer in. Hope you like Theakston's.[attachment=0]oldpeculiergreyhead.jpg[/attachment]
GreyHead 01 Nov, 2010
Hi John,

Many thanks, nice change from the local brew . . .

Yec'hed mat (good health) as they say here.

Bob
This topic is locked and no more replies can be posted.