$portfolio = new portfolio($_SESSION['pfid']); $pf_id = $portfolio->getID(); $pf_name = $portfolio->getName(); $pf_working_date = $portfolio->getWorkingDate(); $pf_exch = $portfolio->getExch()->getID(); $symb = $_GET['symb']; $symb_name = get_symb_name($symb, $pf_exch); $endDate = chartTime2(strtotime($pf_working_date)); if (isset($_SESSION['chart_period'])) { $chart_period = $_SESSION['chart_period']; } else { $chart_period = 180; } $durationInDays = (int) $chart_period; $startDate = $endDate - $durationInDays * 24 * 60 * 60; $first_date = $c->formatValue($startDate, "{value|yyyy-mm-dd}"); $first = true; try { $pdo = new PDO("pgsql:host={$db_hostname};dbname={$db_database}", $db_user, $db_password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die("ERROR: Cannot connect: " . $e->getMessage()); } $query = "select a.date as date, ema_12, ema_26, open, high, low, close from quotes a, moving_averages b where a.date = b.date and a.symb = b.symb and a.exch = b.exch and a.date >= '{$first_date}' and a.date <= '{$pf_working_date}' and a.symb = '{$symb}' and a.exch = '{$pf_exch}' order by a.date limit {$chart_period};"; foreach ($pdo->query($query) as $row) { $open[] = $row['open']; $close[] = $row['close']; $high[] = $row['high']; $low[] = $row['low']; $ema_12[] = $row['ema_12']; $ema_26[] = $row['ema_26'];