0

I am using multiple mysql queries from different databases, pulling out the values from the while loop with arrays and them reuniting them in a loop as this one:

$len = max(count($insrtdate),count($energy));
for($i=0;$i<$len;$i++){
    $date = isset($insrtdate[$i]) ? $insrtdate[$i] : '';
    $energy1 = isset($energy[$i]) ? $energy[$i] : '';
    echo $energy1;
}

The value $energy1 is initially 0 and i want to detect the row in which this changes to any number and the row in which this returns to the initial value of 0.

Toto
  • 89,455
  • 62
  • 89
  • 125

1 Answers1

0

I'm not 100% sure that I understand your question, but this should be what you want:

$len = max(count($insrtdate), count($energy));
$lastEnergy1 = null;
for($i=0; $i < $len; $i++){
    $date = isset($insrtdate[$i]) ? $insrtdate[$i] : '';
    $energy1 = isset($energy[$i]) ? $energy[$i] : '';
    if ($lastEnergy1 !== $energy1) {
    $onState = ($energy1 == "1" ? "on" : "off");
        echo "Energy1 turned " . $onState . " at " . $date . "<br />";
        $lastEnergy1 = $energy1;
    }
}
h2ooooooo
  • 39,111
  • 8
  • 68
  • 102
  • it identifies when the value is not 0 but i want it to show the start and the finish just. Just to be clear this is a power plant that starts and stops several times a day, a chrone sends data to mysql every 10 minutes if it's stopped it send 0 and when it starts it sends the value, i have to determine when it starts and when it stops so i'm looking for something that tells me the row the $energy changed from 0 to a value and the row when the value returned to 0 – Cristian Bican Sep 03 '12 at 13:57
  • Changed my post - is this what you need? – h2ooooooo Sep 03 '12 at 14:04