From ba90d60bc3295a67cf23dbf009d071b9416f82c3 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Tue, 14 Jul 2009 10:06:35 +0000 Subject: [PATCH] Introduce adminer_select_val git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@826 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- adminer/include/adminer.inc.php | 8 ++++++++ adminer/select.inc.php | 36 +++++++++++++++++++-------------- editor/include/adminer.inc.php | 4 ++++ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 633fab65..9937689d 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -57,6 +57,14 @@ function adminer_select_query($query) { return call_adminer('select_query', "

" . htmlspecialchars($query) . " " . lang('Edit') . "\n", $query); } +/** Value printed in select table +* @param string escaped value to print +* @return string link to foreign key +*/ +function adminer_select_val($val, $link) { + return call_adminer('select_val', ($link ? '' . $val . '' : $val), $val, $link); +} + /** Query printed after execution in the message * @param string executed query * @return string diff --git a/adminer/select.inc.php b/adminer/select.inc.php index c256c3c0..b519a548 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -265,6 +265,12 @@ if (!$columns) { if (!$result->num_rows) { echo "

" . lang('No rows.') . "\n"; } else { + $rows = array(); + while ($row = $result->fetch_assoc()) { + $rows[] = $row; + } + $result->free(); + $foreign_keys = array(); foreach (foreign_keys($_GET["select"]) as $foreign_key) { foreach ($foreign_key["source"] as $val) { @@ -273,14 +279,12 @@ if (!$columns) { } echo "\n"; - for ($j=0; $row = $result->fetch_assoc(); $j++) { - if (!$j) { - echo '\n"; - } + echo "\n"; + foreach ($rows as $row) { $unique_idf = implode('&', unique_idf($row, $indexes)); //! don't use aggregation functions echo '
'; - foreach ($row as $key => $val) { - echo '' . adminer_field_name($fields, $key) . ''; - } - echo "
"; + foreach ($rows[0] as $key => $val) { + echo '' . adminer_field_name($fields, $key) . ''; + } + echo "
' . (count($select) != count($group) || information_schema($_GET["db"]) ? '' : ' ' . lang('edit') . ''); foreach ($row as $key => $val) { @@ -302,29 +306,32 @@ if (!$columns) { $val = "$val"; } } + + // link related items + $link = ""; foreach ((array) $foreign_keys[$key] as $foreign_key) { if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) { - // link related items - $val = "\">$val"; foreach ($foreign_key["source"] as $i => $source) { - $val = "&where%5B$i%5D%5Bcol%5D=" . urlencode($foreign_key["target"][$i]) . "&where%5B$i%5D%5Bop%5D=%3D&where%5B$i%5D%5Bval%5D=" . urlencode($row[$source]) . $val; + $link .= "&where%5B$i%5D%5Bcol%5D=" . urlencode($foreign_key["target"][$i]) . "&where%5B$i%5D%5Bop%5D=%3D&where%5B$i%5D%5Bval%5D=" . urlencode($row[$source]); } - $val = '
\n"); echo "
" . lang('Export') . "
$dump_output $dump_format
\n"; } - $result->free(); echo "
" . lang('CSV Import') . "
\n"; //! Editor only diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index b4dea4d8..20def63a 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -28,6 +28,10 @@ function adminer_select_query($query) { return call_adminer('select_query', "\n", $query); } +function adminer_select_val($val, $link) { + return call_adminer('select_val', ($link ? '
' . $val . '' : $val), $val, $link); +} + function adminer_message_query($query) { return call_adminer('message_query', "", $query); }