bug 782828
[phpmyadmin/crack.git] / libraries / get_foreign.lib.php3
blobc4558e8d6a733dbc1787596d6ee982db15f546e7
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * Gets foreign keys in preparation for a drop-down selector
8 * Thanks to <markus@noga.de>
9 */
11 // lem9
12 //if (!defined('PMA_GET_FOREIGN_LIB_INCLUDED')) {
13 // define('PMA_GET_FOREIGN_LIB_INCLUDED', 1);
15 // lem9: we always show the foreign field in the drop-down; if a display
16 // field is defined, we show it besides the foreign field
17 if ($foreigners && isset($foreigners[$field])) {
18 $foreigner = $foreigners[$field];
19 $foreign_db = $foreigner['foreign_db'];
20 $foreign_table = $foreigner['foreign_table'];
21 $foreign_field = $foreigner['foreign_field'];
23 // Count number of rows in the foreign table. Currently we do
24 // not use a drop-down if more than 200 rows in the foreign table,
25 // for speed reasons and because we need a better interface for this.
27 // We could also do the SELECT anyway, with a LIMIT, and ensure that
28 // the current value of the field is one of the choices.
30 $the_total = PMA_countRecords($foreign_db, $foreign_table, TRUE);
32 if ($the_total < 200) {
33 // foreign_display can be FALSE if no display field defined:
35 $foreign_display = PMA_getDisplayField($foreign_db, $foreign_table);
36 $dispsql = 'SELECT ' . PMA_backquote($foreign_field)
37 . (($foreign_display == FALSE) ? '' : ', ' . PMA_backquote($foreign_display))
38 . ' FROM ' . PMA_backquote($foreign_db) . '.' . PMA_backquote($foreign_table)
39 . (($foreign_display == FALSE) ? '' :' ORDER BY ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($foreign_display));
40 $disp = PMA_mysql_query($dispsql);
42 else {
43 unset($disp);
45 } // end if $foreigners
47 //} // $__PMA_GET_FOREIGN_LIB_INCLUDED__