function ResultSetExporter($sql, $headers, $filter = false) { $this->headers = array_values($headers); if ($s = strpos(strtoupper($sql), ' LIMIT ')) { $sql = substr($sql, 0, $s); } # TODO: If $filter, add different LIMIT clause to query $this->_res = db_query($sql); if ($row = db_fetch_array($this->_res)) { $query_fields = array_keys($row); $this->headers = array(); $this->keys = array(); $this->lookups = array(); foreach ($headers as $field => $name) { if (isset($row[$field])) { $this->headers[] = $name; $this->keys[] = $field; # Remember the location of this header in the query results # (column-wise) so we don't have to do hashtable lookups for every # column of every row. $this->lookups[] = array_search($field, $query_fields); } } db_data_reset($this->_res); } }
function ResultSetExporter($sql, $headers) { $this->headers = array_values($headers); $this->_res = db_query($sql); if ($row = db_fetch_array($this->_res)) { $query_fields = array_keys($row); $this->headers = array(); $this->keys = array(); $this->lookups = array(); foreach ($headers as $field => $name) { if (isset($row[$field])) { $this->headers[] = $name; $this->keys[] = $field; # Remember the location of this header in the query results # (column-wise) so we don't have to do hashtable lookups for every # column of every row. $this->lookups[] = array_search($field, $query_fields); } } db_data_reset($this->_res); } }