How to omit the last row of the resultant array if number of rows are odd in php?
<p>i have a mysql table in the following format</p>

<pre><code>     -------------------------------------------------------------------------------------------------------------
    | event_id | event_type | machine    | user      |  timeStamp          | Shift   | Reason             | Count |
     -------------------------------------------------------------------------------------------------------------
    | 101      | Up         | Machine1   | operator1 | 2012-09-06 01:03:55 | Shift1  | Start of The shift | 1     |
    | 102      | Up         | Machine2   | operator2 | 2012-09-06 01:03:55 | Shift1  | Start of The shift | 1     |
    | 103      | Up         | Machine3   | operator3 | 2012-09-06 01:03:55 | Shift1  | Start of The shift | 1     |
    | 104      | Down       | Machine1   | operator1 | 2012-09-06 02:03:55 | Shift1  | Break Down         | 1     |
    | 101      | Up         | Machine1   | operator1 | 2012-09-06 02:33:55 | Shift1  | After BD           | 1     |
     -------------------------------------------------------------------------------------------------------------
</code></pre>

<p>by passing the following query.</p>

<pre><code>  $data = mysql_query("select * from rpt_machine_log where (timestamp between date_sub(now(),INTERVAL 2 WEEK) and now() &amp;&amp; (machine='machine$i') &amp;&amp; (shift='Shift1') ) AND (reason='Start of The Shift' OR reason='End of Shift') ORDER BY 'even_id'") 
</code></pre>

<p>i get the following output</p>

<pre><code>     -------------------------------------------------------------------------------------------------------------
    | event_id | event_type | machine    | user      |  timeStamp          | Shift   | Reason             | Count |
     -------------------------------------------------------------------------------------------------------------
    | 101      | Up         | Machine1   | operator1 | 2012-09-06 01:03:55 | Shift1  | Start of The shift | 1     |
    | 118      | Down       | Machine1   | operator1 | 2012-09-06 06:00:55 | Shift1  | End of The shift   | 1     |
    | 127      | Up         | Machine1   | operator1 | 2012-09-07 01:03:55 | Shift1  | Start of The shift | 1     |
    | 148      | Down       | Machine1   | operator1 | 2012-09-07 02:03:55 | Shift1  | End of The shift   | 1     |
     -------------------------------------------------------------------------------------------------------------
</code></pre>

<p>I calculate Total Shift Time by finding the difference of the End of The shift and Star of The shift like the following code.</p>

<pre><code>     while ($row = mysql_fetch_assoc($shifttime{$i})) 
            {
                if(isset($timestamp))
                {
                    $diff_shift_time{$i}= strtotime($row['timestamp']) - strtotime($timestamp);
                    $diff_shift_time_array{$i}[]=$diff_shift_time{$i};
                    unset($timestamp);
                }
                else
                {
                    $timestamp=$row['timestamp'];
                }
            }

            foreach ($diff_shift_time_array{$i} as &amp;$value){
                $Total_shift_time{$i} += $value;
                }
</code></pre>

<p>in some cases the output of the query is as follows.</p>

<pre><code>     -------------------------------------------------------------------------------------------------------------
    | event_id | event_type | machine    | user      |  timeStamp          | Shift   | Reason             | Count |
     -------------------------------------------------------------------------------------------------------------
    | 121      | Up         | Machine1   | operator1 | 2012-09-06 06:03:55 | Shift2  | Start of The shift | 1     |
    | 124      | Down       | Machine1   | operator1 | 2012-09-06 01:00:55 | Shift2  | End of The shift   | 1     |
    | 151      | Up         | Machine1   | operator1 | 2012-09-07 06:03:55 | Shift2  | Start of The shift | 1     |
     -------------------------------------------------------------------------------------------------------------
</code></pre>

<p>when i calculate the total shift time, i get negative value, because my resultant table ends with Up event.</p>

<p>Since the calculation is for consecutive up and down(<code>so the no of rows of the resultant row should always be even</code>), the last up doesn't have down event to perform calculation. </p>

<p>I want to delete the last row of the table if the row count is odd.</p>

<p>How can i achieve it.</p>
