From e20a959086a9f1a9680c0a1cf89c8782a8f0cdb9 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Fri, 23 Nov 2012 10:27:38 +0100 Subject: sqlbox/view: Put query to table code into own function --- sqlbox/view.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index 5f0e4a0..d095376 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -84,7 +84,20 @@ if (isset($data->sqlbox_query)) { if (!db) error("Failed to connect to sqlbox db"); - $result = pg_query($db, $data->sqlbox_query); + $table = db_get_table_from_query($db, $data->sqlbox_query); + + echo html_writer::table($table); + + pg_close($db); +} + +// Finish the page +echo $OUTPUT->footer(); + + +function db_get_table_from_query($db, $query) { + $table = new html_table; + $result = pg_query($db, $query); if (!$result) error("Query failed: ".pg_last_error($db)); @@ -96,10 +109,6 @@ if (isset($data->sqlbox_query)) { while ($row = pg_fetch_row($result)) $table->data[] = $row; - echo html_writer::table($table); - - pg_close($db); + return $table; } -// Finish the page -echo $OUTPUT->footer(); -- cgit