title: If result is zero use previous. What did i do wrong?
body: <p>I am trying to write a function that returns a mutlidimensional array where the key is the date, and the date has two more items cost and value. with the query i am using the result will be zero rows if the stock market was closed that day (IE weekend or holiday). i want to set that days cost and value equal to the previous. Obviously i am missing something here but i dont understand.</p>
  
  <pre><code>function getNetWorth()
  {
      // Query for First and Last date
      $query = $this-&gt;db-&gt;query("SELECT min(date) as start from Transactions ORDER BY date ASC;");
      $date = $query-&gt;row_array();
      $current = $date['start'];
      $networth = array();
      while(strtotime($current)&lt;= strtotime(date('Y-m-d')))
      {
          $cost = 0;
          $value = 0;
          $run = date('Y-m-d', $current);
          // Query for net worth for given day
          echo $current;
          $sql = "SELECT Transactions.symbol, sum(shares) AS shares, sum(shares * price) AS cost, History.close as `close`, (sum(shares) * History.close) as value ".
                  "FROM Transactions INNER JOIN History ON (History.symbol = Transactions.symbol AND History.date ='".$run."') ".
                  "WHERE (action &lt;&gt;5) AND Transactions.date &lt;= '".$run."' GROUP BY Transactions.symbol HAVING sum(shares) &gt; 0";
          $query = $this-&gt;db-&gt;query($sql);
          if($query-&gt;num_rows() &lt; 1)
          {
  
              $date = strtotime("-1 day", $current);
              $last = date('Y-m-d', $date);
          //  $networth[$current][] = $networth[$last];
          }
          else
          {
              $result = $query-&gt;result_array();
              $cost += $result['cost'];
              $value += $result['value'];
              $networth[$current]= array("cost" =&gt; $cost, "value" =&gt; $value);
  
          }
  
  
          $current = strtotime("+1 day", strtotime($current));    
      }
      return $networth;
  }
  </code></pre>