Link to home
Start Free TrialLog in
Avatar of fcruz5
fcruz5Flag for United States of America

asked on

Same Results in Table Data

I have two PHP files. One is totals.php and the other one is reports.php. The totals are displayed in report.php through a session variable.

In report.php it repeats the same total for every result with the following:

$_SESSION["sum1"] = $sum1;
$_SESSION["sum2"] = $sum2;
$_SESSION["avg1"] = $avg1/$sum;


How can I make it so that it will not repeat the same results?

PHP Code:


<?php

//============ in totals.php
session_start();
// code here...
echo "<tr>
<td>".($sum-$empty1)."</td>
<td>$sum1</td> // This total displays in report.php
<td>$sum2</td> // This total displays in report.php
<td>".($avg4/$sum)."%</td> // This total displays report.php
</tr>";


$_SESSION["sum1"] = $sum1;
$_SESSION["sum2"] = $sum2;
$_SESSION["avg1"] = $avg1/$sum;

// more code here

session_write_close();


//============ in report.php
session_start();
// your code here...

foreach ($resultArray as $val) {
   echo ('<tr>');//first row
   if (($rowcount%2) == 0) {
        $css_class = "\"row\"";
    } else {
        $css_class = "\"alt\"";
    }

      echo ('<td class=' . $css_class . ' align=default >'.$val[1].'</td>'); //total
      echo ('<td class=' . $css_class . ' align=default >'.$_SESSION["sum1"].'</td>'); // REPEATS
      echo ('<td class=' . $css_class . ' align=default >'.$_SESSION["sum2"].'</td>'); // REPEATS
      echo ('<td class=' . $css_class . ' align=default >'.$_SESSION["avg1"].'</td>'); //REPEATS
    echo ('</tr>');
}

// More code here...
session_write_close();

?>
SOLUTION
Avatar of Joe Wu
Joe Wu
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial