summaryrefslogtreecommitdiff
path: root/sqlbox/view.php
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-23 10:27:38 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-23 10:34:10 +0100
commite20a959086a9f1a9680c0a1cf89c8782a8f0cdb9 (patch)
tree4276ab1eab540c07be21770612c5376503db6685 /sqlbox/view.php
parent42f8bbbee199cc2bb93a5d3896bfa14dfa2f4c60 (diff)
downloadsqltutor-plugin-e20a959086a9f1a9680c0a1cf89c8782a8f0cdb9.tar.gz
sqltutor-plugin-e20a959086a9f1a9680c0a1cf89c8782a8f0cdb9.tar.bz2
sqltutor-plugin-e20a959086a9f1a9680c0a1cf89c8782a8f0cdb9.zip
sqlbox/view: Put query to table code into own function
Diffstat (limited to 'sqlbox/view.php')
-rw-r--r--sqlbox/view.php21
1 files changed, 15 insertions, 6 deletions
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();