[ Index ] |
|
Code source de phpMyAdmin 2.10.3 |
1 <?php 2 /* $Id: get_foreign.lib.php 8609 2006-02-21 11:07:46Z cybot_tm $ */ 3 // vim: expandtab sw=4 ts=4 sts=4: 4 5 6 require_once './libraries/Table.class.php'; 7 8 /** 9 * Gets foreign keys in preparation for a drop-down selector 10 * Thanks to <markus@noga.de> 11 */ 12 13 14 // lem9: we always show the foreign field in the drop-down; if a display 15 // field is defined, we show it besides the foreign field 16 $foreign_link = false; 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']; 22 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. 26 // 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. 29 30 $the_total = PMA_Table::countRecords($foreign_db, $foreign_table, TRUE); 31 32 if ((isset($override_total) && $override_total == true) || $the_total < $cfg['ForeignKeyMaxLimit']) { 33 // foreign_display can be FALSE if no display field defined: 34 $foreign_display = PMA_getDisplayField($foreign_db, $foreign_table); 35 36 $f_query_main = 'SELECT ' . PMA_backquote($foreign_field) 37 . (($foreign_display == FALSE) ? '' : ', ' . PMA_backquote($foreign_display)); 38 $f_query_from = ' FROM ' . PMA_backquote($foreign_db) . '.' . PMA_backquote($foreign_table); 39 $f_query_filter = empty($foreign_filter) ? '' : ' WHERE ' . PMA_backquote($foreign_field) 40 . ' LIKE "%' . PMA_sqlAddslashes($foreign_filter, TRUE) . '%"' 41 . (($foreign_display == FALSE) ? '' : ' OR ' . PMA_backquote($foreign_display) 42 . ' LIKE "%' . PMA_sqlAddslashes($foreign_filter, TRUE) . '%"' 43 ); 44 $f_query_order = ($foreign_display == FALSE) ? '' :' ORDER BY ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($foreign_display); 45 $f_query_limit = isset($foreign_limit) ? $foreign_limit : ''; 46 47 if (!empty($foreign_filter)) { 48 $res = PMA_DBI_query('SELECT COUNT(*)' . $f_query_from . $f_query_filter); 49 if ($res) { 50 $the_total = PMA_DBI_fetch_value($res); 51 @PMA_DBI_free_result($res); 52 } else { 53 $the_total = 0; 54 } 55 } 56 57 $disp = PMA_DBI_query($f_query_main . $f_query_from . $f_query_filter . $f_query_order . $f_query_limit); 58 if ($disp) { 59 // garvin: If a resultset has been created, pre-cache it in the $disp_row array 60 // This helps us from not needing to use mysql_data_seek by accessing a pre-cached 61 // PHP array. Usually those resultsets are not that big, so a performance hit should 62 // not be expected. 63 $disp_row = array(); 64 while ($single_disp_row = @PMA_DBI_fetch_assoc($disp)) { 65 $disp_row[] = $single_disp_row; 66 } 67 @PMA_DBI_free_result($disp); 68 } 69 } else { 70 unset($disp_row); 71 $foreign_link = true; 72 } 73 } // end if $foreigners 74 75 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 15:18:20 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |