troubleshooting Question

Same Results in Table Data

Avatar of fcruz5
fcruz5Flag for United States of America asked on
PHP
2 Comments2 Solutions196 ViewsLast Modified:
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();

?>
ASKER CERTIFIED SOLUTION
CharlesWilkinsIV

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros