Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum values in an array containing both text and numeric data?

Status
Not open for further replies.

Apollo6

Technical User
Jan 27, 2000
418
US
I want to summarize an array. I have looked at array_sum() but for some reason, the function is not recognized so I am not able to use it??? I am using version 4.3.1. Am I missing a module or something that will allow me to use the array_sum() function? It seems to be exactly what I need.

For example:

employee type hours rate
fred regular 8 5.25
fred regular 5 5.25
fred regular 7 5.25
fred sick 8 5.25
fred sick 8 5.25

summarized array:
fred regular 20 5.25
fred sick 16 5.25
 
Can we see an example of your code that is not working?

Thanks
Ken
 
The following gives me the results of the array but not rolled up (grouped and summarized).

<?
include_once("logonpsql.inc");
include_once("logonemp.inc");
session_start();

$_SESSION['SESSION_UID'] = $_POST["user_id"];
$_SESSION['SESSION_PW'] = $_POST["passwd"];
$_SESSION['SESSION_PERIOD'] = $_POST['perend'];

$user_id = $_SESSION['SESSION_UID'];
$passwd = $_SESSION['SESSION_PW'];
$periodend = $_SESSION['SESSION_PERIOD'];
$ss_num = $_SESSION['SESSION_SSN'];

$mod_date = explode("/",$periodend);
$mod_date = $mod_date[2] . $mod_date[0] . $mod_date[1];

$connection = pg_connect ("host=$host dbname=$db user=$user
password=$pass");
if (!$connection)
{
die("Could not open connection to PostgreSQL");
}

$connect_soinc = odbc_connect("$sodb","$souser","$sopass");
if (!$connect_soinc)
{
die("Error in SOINC connection");
}
$connect_topllc = odbc_connect("$todb","$touser","$topass");
if (!$connect_topllc)
{
die("Error in TOPLLC connection");
}
?>
<?
$s_query1 = "SELECT UPCHKD.EMPLOYEE, UPCHKD.PEREND, UPCHKD.EARNDED, UPCHKD.HOURS, UPCHKD.ERATE, UPCHKD.EEXTEND, UPCHKD.TAXEARNS
FROM
soinc.UPEMPL UPEMPL LEFT JOIN soinc.UPCHKD UPCHKD ON
UPEMPL.EMPLOYEE = UPCHKD.EMPLOYEE
WHERE
UPEMPL.SSN = '$ss_num' AND
UPCHKD.PEREND = $mod_date";

$s_query2 = "SELECT COUNT(*)
FROM
soinc.UPEMPL
WHERE UPEMPL.SSN = '$ss_num' AND
UPEMPL.STATUS = 1";

$s_query3 = "SELECT UPEMPL.FIRSTNAME, UPEMPL.LASTNAME
FROM
soinc.UPEMPL
WHERE
UPEMPL.SSN = '$ss_num' AND
UPEMPL.STATUS = 1";

$s_result1 = odbc_exec($connect_soinc, $s_query1);
$s_result2 = odbc_exec($connect_soinc, $s_query2);
$s_result3 = odbc_exec($connect_soinc, $s_query3);
$s_count=(int)odbc_result($s_result2,1);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Online Paycheck</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" background="background2.gif">
<form name="SubMain" action="paycheck.php" method="post">
<table width="781" border="0" cellspacing="10" cellpadding="5">
<!--DWLayoutTable-->
<tr>
<td height="29" colspan="3" valign="top"><div align="center">&nbsp;
<?
echo "<strong>Paycheck Data for " . "$periodend</strong>";
?>
</div></td>
<td width="169"></td>
</tr>
<tr>
<td width="125" height="29" valign="top"><div align="left"><font face="Arial, Helvetica, sans-serif">Employee
Name:</font></div></td>
<td width="159" align="left" valign="top">
<?
if ($s_count > 0)
{
echo odbc_result($s_result3, 1);
echo odbc_result($s_result3, 2);
}
//else
//if ($t_count > 0)
//{
//echo odbc_result($t_result5, 10);
//}
?>
</td>
<td width="238"></td>
<td></td>
</tr>
<tr>
<td height="29" valign="top"><font face="Arial, Helvetica, sans-serif">Current
Earnings:</font></td>
<td align="left" valign="top">
<?
if ($s_count > 0)
{
$rows = odbc_result_all($s_result1);
}
?>&nbsp;</td>
<td></td>
<td></td>
</tr>
<tr>
<td height="475">&nbsp;</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</form>
</body>
</html>
 
Just to try and help narrow it down, $s_result1 is the array that contains the records that need to be summarized.

Thanks Again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top