From a12ea6f9913c82f9946ce59971699857d8f58f4b Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Thu, 3 Oct 2002 21:21:46 +0000 Subject: [PATCH] new --- libraries/get_foreign.lib.php3 | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 libraries/get_foreign.lib.php3 diff --git a/libraries/get_foreign.lib.php3 b/libraries/get_foreign.lib.php3 new file mode 100755 index 000000000..8e0b6928f --- /dev/null +++ b/libraries/get_foreign.lib.php3 @@ -0,0 +1,35 @@ + + // get foreign keys in preparation for a drop-down selector + + // lem9: we always show the foreign field in the drop-down; if a display + // field is defined, we show it besides the foreign field + if ($foreigners && isset($foreigners[$field])) { + $foreigner = $foreigners[$field]; + $foreign_db = $foreigner['foreign_db']; + $foreign_table = $foreigner['foreign_table']; + $foreign_field = $foreigner['foreign_field']; + + // Count number of rows in the foreign table. Currently we do + // not use a drop-down if more than 200 rows in the foreign table, + // for speed reasons and because we need a better interface for this. + // + // We could also do the SELECT anyway, with a LIMIT, and ensure that + // the current value of the field is one of the choices. + + $count_query = 'SELECT COUNT(*) AS total FROM ' . PMA_backquote($foreign_db) . '.' . PMA_backquote($foreign_table); + $count_result = PMA_mysql_query($count_query) or PMA_mysqlDie('', $count_query, '', $err_url); + $the_total = PMA_mysql_result($count_result, 0, 'total'); + mysql_free_result($count_result); + + if ($the_total < 200) { + // foreign_display can be FALSE if no display field defined: + $foreign_display = PMA_getDisplayField($foreign_db, $foreign_table); + $dispsql = 'SELECT ' . PMA_backquote($foreign_field) + . (($foreign_display == FALSE) ? '' : ', ' . PMA_backquote($foreign_display)) + . ' FROM ' . PMA_backquote($foreign_db) . '.' . PMA_backquote($foreign_table) + . ' ORDER BY ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($foreign_display); + $disp = PMA_mysql_query($dispsql); + } + } // end if $foreigners +?>