From 07adb8da8ed37adcb29b50b34b4717f13f180c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 12 Oct 2005 09:01:04 +0000 Subject: [PATCH] Fix paging. --- ChangeLog | 3 +++ libraries/get_foreign.lib.php | 30 +++++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2fdee1477..a0bc1fad5 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ phpMyAdmin - Changelog $Id$ $Source$ +2005-10-12 Michal Čihař + * libraries/get_foreign.lib.php: Fix paging. + 2005-10-11 Marc Delisle * libraries/grab_globals.lib.php: bug #1322871, local file inclusion diff --git a/libraries/get_foreign.lib.php b/libraries/get_foreign.lib.php index 8f5b96a5c..a1e1ad43f 100644 --- a/libraries/get_foreign.lib.php +++ b/libraries/get_foreign.lib.php @@ -29,20 +29,29 @@ if ($foreigners && isset($foreigners[$field])) { if ((isset($override_total) && $override_total == true) || $the_total < $cfg['ForeignKeyMaxLimit']) { // 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) - . (empty($foreign_filter) ? '' : ' WHERE ' . PMA_backquote($foreign_field) + + $f_query_main = 'SELECT ' . PMA_backquote($foreign_field) + . (($foreign_display == FALSE) ? '' : ', ' . PMA_backquote($foreign_display)); + $f_query_from = ' FROM ' . PMA_backquote($foreign_db) . '.' . PMA_backquote($foreign_table); + $f_query_filter = empty($foreign_filter) ? '' : ' WHERE ' . PMA_backquote($foreign_field) . ' LIKE "%' . PMA_sqlAddslashes($foreign_filter, TRUE) . '%"' . (($foreign_display == FALSE) ? '' : ' OR ' . PMA_backquote($foreign_display) . ' LIKE "%' . PMA_sqlAddslashes($foreign_filter, TRUE) . '%"' - ) - ) - . (($foreign_display == FALSE) ? '' :' ORDER BY ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($foreign_display)) - . (isset($foreign_limit) ? $foreign_limit : ''); - $disp = PMA_DBI_query($dispsql); + ); + $f_query_order = ($foreign_display == FALSE) ? '' :' ORDER BY ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($foreign_display); + $f_query_limit = isset($foreign_limit) ? $foreign_limit : ''; + + if (!empty($foreign_filter)) { + $res = PMA_DBI_query('SELECT COUNT(*)' . $f_query_from . $f_query_filter); + if ($res) { + $the_total = PMA_DBI_fetch_value($res); + } else { + $the_total = 0; + } + } + + $disp = PMA_DBI_query($f_query_main . $f_query_from . $f_query_filter . $f_query_order . $f_query_limit); if ($disp) { // garvin: If a resultset has been created, pre-cache it in the $disp_row array // This helps us from not needing to use mysql_data_seek by accessing a pre-cached @@ -52,7 +61,6 @@ if ($foreigners && isset($foreigners[$field])) { while ($single_disp_row = @PMA_DBI_fetch_assoc($disp)) { $disp_row[] = $single_disp_row; } - $the_total = count($disp_row); @PMA_DBI_free_result($disp); } }