//    if(empty($otherColumns)){
//    	echo("Please select the columns!");
//    }else{
//        for($i=0; $i < count($otherColumns); $i++){
//			$valueColumns .= "`" . $otherColumns[$i] . "` as 'valueColumn" . $i . "'";
//			if(!empty($otherColumns[$i+1])){
//				$valueColumns .= ", ";
//			}
//      }
//}
//	$sql = "SELECT `" . $firstColumn . "` as 'firstColumn', `" . $dateColumn . "` as 'dateColumn', ";
//	$sql .= $valueColumns;
//	$sql .= " FROM resultDoJoin ";
//	if (!empty($where))
//      $sql .= $where;
$rst = ExternalMSSQL::runQueryWithLinkedServers($query);
//	$rst = $db->get_results($sql);
$rows = array();
foreach ($rst as $r) {
    $rows[] = $r;
}
echo json_encode($rows);
/*
$titleNo = 0;
$firstColumn = "Location";
$dateColumn = "Spd";
$otherColumns = ['Households','Married Couples'];
*/
/*
$cols = "";
for($i=0; $i<count($otherColumns); $i++) {
    private static function makeQueryToRotateTable($sid, $table_name, $dnamesToInclude)
    {
        $colsResult = ExternalMSSQL::getAllTableNameDotColumnsBySid($sid, $table_name);
        $colsRenamed = $colsResult->colsRenamed;
        $cols = $colsResult->originalCols;
        $query = <<<EOQ
    select {$colsRenamed}
\t\tfrom
\t\t(
\t\t\tselect *
\t\t\tfrom
    \t\t\t(select rownum, Dname, Value from [COLFUSIONDEV]...colfusion_temporary where sid = {$sid}) as T
\t\t\t\t pivot
\t\t\t\t(
\t\t\t\t\tmax(T.VALUE)
\t\t\t\t\tfor T.Dname in ({$cols})
\t\t\t\t) as P
\t\t) as rot 
EOQ;
        return $query;
    }