Hello guys,

Working on a stock market table with rates of different currencies.

What I would like to achieve is that i have an array of rates and would like the difference of today and the previous day, and it works, but i'm getting an empty value for the first row, which i dont know how to escape.

                                while($arr = mysql_fetch_array($sql))
                                {
                                    if(!is_null($previous) && $previous['euro'] == $arr['euro'])
                                    {
                                        $euro = '';
                                        $usd = ''; 
                                    }
                                    else
                                    {
                                        $euro = $previous['euro']-$arr['euro'];
                                        $usd = $previous['usd']-$arr['usd'];
                                        $huf = $previous['huf']-$arr['huf'];

                                        if('-'.$arr['euro'] == $euro)
                                        {
                                            $euro_ok = null;
                                            $usd_ok = null;
                                            $huf_ok = null;
                                        }
                                        else
                                        {
                                            $euro_ok = $euro;
                                            $usd_ok = $usd;
                                            $huf_ok = $huf;
                                        }

                                        $data .= '<tr><td style="width: 100px; background-color: #CCC;">'.date("d-M-Y", strtotime($arr['data'])).'</td><td>'.$arr['euro'].'</td><td>'.$this->formatare($euro_ok).'</td><td>'.$arr['usd'].'</td><td>'.$this->formatare($usd_ok).'</td><td>'.$arr['huf'].'</td><td>'.$this->formatare($huf_ok).'</td></tr>';
                                    }

                                    $previous = $arr;
                                    $i++;
                                }

Untitled32

for first case your previous element is blank, you are setting it at line 30. So you must have some reference value in the begingin for $previous

Yes it's blank, it's getting the same value as the first element, i've tried to eliminate it so the first value should be my second row :(

try this, add 1 lines before while

$previous = mysql_fetch_array($sql)

  while($arr = mysql_fetch_array($sql))
  {

I dont think that that would be the solution, there is something else ...

try this

$arr = mysql_fetch_array($sql);
                                while($previous = mysql_fetch_array($sql))
                                {
                                    if(!is_null($previous) && $previous['euro'] == $arr['euro'])
                                    {
                                        $euro = '';
                                        $usd = ''; 
                                    }
                                    else
                                    {
                                        $euro = $previous['euro']-$arr['euro'];
                                        $usd = $previous['usd']-$arr['usd'];
                                        $huf = $previous['huf']-$arr['huf'];

                                        if('-'.$arr['euro'] == $euro)
                                        {
                                            $euro_ok = null;
                                            $usd_ok = null;
                                            $huf_ok = null;
                                        }
                                        else
                                        {
                                            $euro_ok = $euro;
                                            $usd_ok = $usd;
                                            $huf_ok = $huf;
                                        }

                                        $data .= '<tr><td style="width: 100px; background-color: #CCC;">'.date("d-M-Y", strtotime($arr['data'])).'</td><td>'.$arr['euro'].'</td><td>'.$this->formatare($euro_ok).'</td><td>'.$arr['usd'].'</td><td>'.$this->formatare($usd_ok).'</td><td>'.$arr['huf'].'</td><td>'.$this->formatare($huf_ok).'</td></tr>';
                                    }

                                     $arr=$previous;
                                    $i++;
                                }

That was it!!! :) I knew it that I am mixing it up! :)

Thanks urtrivedi!