2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * query by example the whole database
12 require_once './libraries/common.inc.php';
13 require_once './libraries/Table.class.php';
14 require_once './libraries/relation.lib.php';
18 * Gets the relation settings
20 $cfgRelation = PMA_getRelationsParam();
24 * A query has been submitted -> execute it, else display the headers
26 if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {
28 $zero_rows = htmlspecialchars($GLOBALS['strSuccess']);
33 require './libraries/db_common.inc.php';
34 $url_query .= '&goto=db_qbe.php';
35 $url_params['goto'] = 'db_qbe.php';
36 require './libraries/db_info.inc.php';
39 if (isset($_REQUEST['submit_sql'])
40 && ! preg_match('@^SELECT@i', $sql_query)) {
41 PMA_Message
::warning('strHaveToShow')->display();
46 * Initialize some variables
48 $col_cnt = PMA_ifSetOr($_REQUEST['col_cnt'], 3, 'numeric');
49 $add_col = PMA_ifSetOr($_REQUEST['add_col'], 0, 'numeric');
50 $add_row = PMA_ifSetOr($_REQUEST['add_row'], 0, 'numeric');
52 $rows = PMA_ifSetOr($_REQUEST['rows'], 0, 'numeric');
53 $ins_col = PMA_ifSetOr($_REQUEST['ins_col'], null, 'array');
54 $del_col = PMA_ifSetOr($_REQUEST['del_col'], null, 'array');
56 $prev_criteria = isset($_REQUEST['prev_criteria'])
57 ?
$_REQUEST['prev_criteria']
59 $criteria = isset($_REQUEST['criteria'])
60 ?
$_REQUEST['criteria']
61 : array_fill(0, $col_cnt, '');
63 $ins_row = isset($_REQUEST['ins_row'])
64 ?
$_REQUEST['ins_row']
65 : array_fill(0, $col_cnt, '');
66 $del_row = isset($_REQUEST['del_row'])
67 ?
$_REQUEST['del_row']
68 : array_fill(0, $col_cnt, '');
69 $and_or_row = isset($_REQUEST['and_or_row'])
70 ?
$_REQUEST['and_or_row']
71 : array_fill(0, $col_cnt, '');
72 $and_or_col = isset($_REQUEST['and_or_col'])
73 ?
$_REQUEST['and_or_col']
74 : array_fill(0, $col_cnt, '');
77 $form_column_width = 12;
78 $col = max($col_cnt +
$add_col, 0);
79 $row = max($rows +
$add_row, 0);
82 // The tables list sent by a previously submitted form
83 if (PMA_isValid($_REQUEST['TableList'], 'array')) {
84 foreach ($_REQUEST['TableList'] as $each_table) {
85 $tbl_names[$each_table] = ' selected="selected"';
90 // this was a work in progress, deactivated for now
91 //$columns = PMA_DBI_get_columns_full($GLOBALS['db']);
92 //$tables = PMA_DBI_get_columns_full($GLOBALS['db']);
98 $tbl_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE
);
99 $tbl_result_cnt = PMA_DBI_num_rows($tbl_result);
100 if (0 == $tbl_result_cnt) {
101 PMA_Message
::error('strNoTablesFound')->display();
102 require_once './libraries/footer.inc.php';
106 // The tables list gets from MySQL
107 while (list($tbl) = PMA_DBI_fetch_row($tbl_result)) {
108 $fld_results = PMA_DBI_get_fields($db, $tbl);
110 if (empty($tbl_names[$tbl]) && !empty($_REQUEST['TableList'])) {
111 $tbl_names[$tbl] = '';
113 $tbl_names[$tbl] = ' selected="selected"';
116 // The fields list per selected tables
117 if ($tbl_names[$tbl] == ' selected="selected"') {
118 $each_table = PMA_backquote($tbl);
119 $fld[] = $each_table . '.*';
120 foreach ($fld_results as $each_field) {
121 $each_field = $each_table . '.' . PMA_backquote($each_field['Field']);
122 $fld[] = $each_field;
124 // increase the width if necessary
125 $form_column_width = max(strlen($each_field), $form_column_width);
129 PMA_DBI_free_result($tbl_result);
131 // largest width found
132 $realwidth = $form_column_width . 'ex';
136 * Displays the Query by example form
140 * Enter description here...
142 * @param array $columns
143 * @param numeric $column_number
144 * @param string $selected
146 function showColumnSelectCell($columns, $column_number, $selected = '')
150 <select name
="Field[<?php echo $column_number; ?>]" size
="1">
151 <option value
=""> 
;</option
>
153 foreach ($columns as $column) {
154 if ($column === $selected) {
155 $sel = ' selected="selected"';
159 echo '<option value="' . htmlspecialchars($column) . '"' . $sel . '>'
160 . str_replace(' ', ' ', htmlspecialchars($column)) . '</option>' . "\n";
170 <form action
="db_qbe.php" method
="post">
171 <table
class="data" style
="width: 100%;">
172 <tr
class="odd noclick">
173 <th
><?php
echo $strField; ?
>:</th
>
176 for ($x = 0; $x < $col; $x++
) {
177 if (isset($ins_col[$x]) && $ins_col[$x] == 'on') {
178 showColumnSelectCell($fld, $z);
182 if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
187 if (isset($Field[$x])) {
188 $selected = $Field[$x];
189 $curField[$z] = $Field[$x];
191 showColumnSelectCell($fld, $z, $selected);
198 <tr
class="even noclick">
199 <th
><?php
echo $strSort; ?
>:</th
>
202 for ($x = 0; $x < $col; $x++
) {
203 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
206 <select style
="width: <?php echo $realwidth; ?>" name
="Sort[<?php echo $z; ?>]" size
="1">
207 <option value
=""> 
;</option
>
208 <option value
="ASC"><?php
echo $strAscending; ?
></option
>
209 <option value
="DESC"><?php
echo $strDescending; ?
></option
>
217 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
222 <select style
="width: <?php echo $realwidth; ?>" name
="Sort[<?php echo $z; ?>]" size
="1">
223 <option value
=""> 
;</option
>
227 // If they have chosen all fields using the * selector,
228 // then sorting is not available
229 // Robbat2 - Fix for Bug #570698
230 if (isset($Sort[$x]) && isset($Field[$x])
231 && substr($Field[$x], -2) == '.*') {
235 if (isset($Sort[$x]) && $Sort[$x] == 'ASC') {
236 $curSort[$z] = $Sort[$x];
237 $sel = ' selected="selected"';
242 echo '<option value="ASC"' . $sel . '>' . $strAscending . '</option>' . "\n";
243 if (isset($Sort[$x]) && $Sort[$x] == 'DESC') {
244 $curSort[$z] = $Sort[$x];
245 $sel = ' selected="selected"';
250 echo '<option value="DESC"' . $sel . '>' . $strDescending . '</option>' . "\n";
262 <tr
class="odd noclick">
263 <th
><?php
echo $strShow; ?
>:</th
>
266 for ($x = 0; $x < $col; $x++
) {
267 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
270 <input type
="checkbox" name
="Show[<?php echo $z; ?>]" />
277 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
280 if (isset($Show[$x])) {
281 $checked = ' checked="checked"';
282 $curShow[$z] = $Show[$x];
288 <input type
="checkbox" name
="Show[<?php echo $z; ?>]"<?php
echo $checked; ?
> />
297 <!-- Criteria row
-->
298 <tr
class="even noclick">
299 <th
><?php
echo $strCriteria; ?
>:</th
>
302 for ($x = 0; $x < $col; $x++
) {
303 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
306 <input type
="text" name
="criteria[<?php echo $z; ?>]" value
="" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
313 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
316 if (isset($criteria[$x])) {
317 $stripped_Criteria = $criteria[$x];
319 if ((empty($prev_criteria) ||
!isset($prev_criteria[$x]))
320 ||
$prev_criteria[$x] != htmlspecialchars($stripped_Criteria)) {
321 $curCriteria[$z] = $stripped_Criteria;
323 $curCriteria[$z] = $prev_criteria[$x];
327 <input type
="hidden" name
="prev_criteria[<?php echo $z; ?>]" value
="<?php echo htmlspecialchars($curCriteria[$z]); ?>" />
328 <input type
="text" name
="criteria[<?php echo $z; ?>]" value
="<?php echo htmlspecialchars($stripped_Criteria); ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
337 <!-- And/Or columns
and rows
-->
341 for ($y = 0; $y <= $row; $y++
) {
342 if (isset($ins_row[$y]) && $ins_row[$y] == 'on') {
343 $chk['or'] = ' checked="checked"';
346 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">
347 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
348 <!-- Row controls
-->
349 <table cellpadding
="0" cellspacing
="0" border
="0">
351 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
352 <small
><?php
echo $strQBEIns; ?
>:</small
>
353 <input type
="checkbox" name
="ins_row[<?php echo $w; ?>]" />
355 <td align
="<?php echo $cell_align_right; ?>">
356 <strong
><?php
echo $strAnd; ?
>:</strong
>
359 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
364 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
365 <small
><?php
echo $strQBEDel; ?
>:</small
>
366 <input type
="checkbox" name
="del_row[<?php echo $w; ?>]" />
368 <td align
="<?php echo $cell_align_right; ?>">
369 <strong
><?php
echo $strOr; ?
>:</strong
>
372 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
380 for ($x = 0; $x < $col; $x++
) {
381 if (isset($ins_col[$x]) && $ins_col[$x] == 'on') {
383 $or = 'Or' . $w . '[' . $z . ']';
386 <textarea cols
="20" rows
="2" style
="width: <?php echo $realwidth; ?>" name
="<?php echo $or; ?>" dir
="<?php echo $text_dir; ?>"></textarea
>
391 if (isset($del_col[$x]) && $del_col[$x] == 'on') {
396 $or = 'Or' . $w . '[' . $z . ']';
399 <textarea cols
="20" rows
="2" style
="width: <?php echo $realwidth; ?>" name
="<?php echo $or; ?>" dir
="<?php echo $text_dir; ?>"></textarea
>
409 $odd_row =! $odd_row;
412 if (isset($del_row[$y]) && $del_row[$y] == 'on') {
416 if (isset($and_or_row[$y])) {
417 $curAndOrRow[$w] = $and_or_row[$y];
419 if (isset($and_or_row[$y]) && $and_or_row[$y] == 'and') {
420 $chk['and'] = ' checked="checked"';
423 $chk['or'] = ' checked="checked"';
428 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">
429 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
430 <!-- Row controls
-->
431 <table border
="0" cellpadding
="0" cellspacing
="0">
433 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
434 <small
><?php
echo $strQBEIns; ?
>:</small
>
435 <input type
="checkbox" name
="ins_row[<?php echo $w; ?>]" />
437 <td align
="<?php echo $cell_align_right; ?>">
438 <strong
><?php
echo $strAnd; ?
>:</strong
>
441 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
445 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
446 <small
><?php
echo $strQBEDel; ?
>:</small
>
447 <input type
="checkbox" name
="del_row[<?php echo $w; ?>]" />
449 <td align
="<?php echo $cell_align_right; ?>">
450 <strong
><?php
echo $strOr; ?
>:</strong
>
453 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
460 for ($x = 0; $x < $col; $x++
) {
461 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
463 $or = 'Or' . $w . '[' . $z . ']';
466 <textarea cols
="20" rows
="2" style
="width: <?php echo $realwidth; ?>" name
="<?php echo $or; ?>" dir
="<?php echo $text_dir; ?>"></textarea
>
471 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
477 if (!isset($
{$or})) {
480 if (!empty($
{$or}) && isset($
{$or}[$x])) {
481 $stripped_or = $
{$or}[$x];
487 <textarea cols
="20" rows
="2" style
="width: <?php echo $realwidth; ?>" name
="Or<?php echo $w . '[' . $z . ']'; ?>" dir
="<?php echo $text_dir; ?>"><?php
echo htmlspecialchars($stripped_or); ?
></textarea
>
490 if (!empty($
{$or}) && isset($
{$or}[$x])) {
491 $
{'cur' . $or}[$z] = $
{$or}[$x];
501 $odd_row =! $odd_row;
504 <!-- Modify columns
-->
505 <tr
class="even noclick">
506 <th
><?php
echo $strModify; ?
>:</th
>
509 for ($x = 0; $x < $col; $x++
) {
510 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
511 $curAndOrCol[$z] = $and_or_col[$y];
512 if ($and_or_col[$z] == 'or') {
513 $chk['or'] = ' checked="checked"';
516 $chk['and'] = ' checked="checked"';
521 <strong
><?php
echo $strOr; ?
>:</strong
>
522 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
523  
; 
;<strong
><?php
echo $strAnd; ?
>:</strong
>
524 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
526 <?php
echo $strQBEIns . "\n"; ?
>
527 <input type
="checkbox" name
="ins_col[<?php echo $z; ?>]" />
528  
; 
;<?php
echo $strQBEDel . "\n"; ?
>
529 <input type
="checkbox" name
="del_col[<?php echo $z; ?>]" />
536 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
540 if (isset($and_or_col[$y])) {
541 $curAndOrCol[$z] = $and_or_col[$y];
543 if (isset($and_or_col[$z]) && $and_or_col[$z] == 'or') {
544 $chk['or'] = ' checked="checked"';
547 $chk['and'] = ' checked="checked"';
552 <strong
><?php
echo $strOr; ?
>:</strong
>
553 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
554  
; 
;<strong
><?php
echo $strAnd; ?
>:</strong
>
555 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
557 <?php
echo $strQBEIns . "\n"; ?
>
558 <input type
="checkbox" name
="ins_col[<?php echo $z; ?>]" />
559  
; 
;<?php
echo $strQBEDel . "\n"; ?
>
560 <input type
="checkbox" name
="del_col[<?php echo $z; ?>]" />
570 <!-- Other controls
-->
573 $url_params['db'] = $db;
574 $url_params['col_cnt'] = $z;
575 $url_params['rows'] = $w;
576 echo PMA_generate_common_hidden_inputs($url_params);
579 <fieldset
class="tblFooters">
580 <table border
="0" cellpadding
="2" cellspacing
="1">
583 <?php
echo $strAddDeleteRow; ?
>:
584 <select size
="1" name
="add_row" style
="vertical-align: middle">
585 <option value
="-3">-3</option
>
586 <option value
="-2">-2</option
>
587 <option value
="-1">-1</option
>
588 <option value
="0" selected
="selected">0</option
>
589 <option value
="1">1</option
>
590 <option value
="2">2</option
>
591 <option value
="3">3</option
>
594 <td width
="10"> 
;</td
>
595 <td nowrap
="nowrap"><?php
echo $strAddDeleteColumn; ?
>:
596 <select size
="1" name
="add_col" style
="vertical-align: middle">
597 <option value
="-3">-3</option
>
598 <option value
="-2">-2</option
>
599 <option value
="-1">-1</option
>
600 <option value
="0" selected
="selected">0</option
>
601 <option value
="1">1</option
>
602 <option value
="2">2</option
>
603 <option value
="3">3</option
>
606 <td width
="10"> 
;</td
>
607 <!-- Generates a query
-->
608 <td
><input type
="submit" name
="modify" value
="<?php echo $strUpdateQuery; ?>" /></td
>
616 <legend
><?php
echo $strUseTables; ?
></legend
>
618 $strTableListOptions = '';
619 $numTableListOptions = 0;
620 foreach ($tbl_names as $key => $val) {
621 $strTableListOptions .= ' ';
622 $strTableListOptions .= '<option value="' . htmlspecialchars($key) . '"' . $val . '>'
623 . str_replace(' ', ' ', htmlspecialchars($key)) . '</option>' . "\n";
624 $numTableListOptions++
;
627 <select name
="TableList[]" multiple
="multiple" id
="listTable"
628 size
="<?php echo ($numTableListOptions > 30) ? '15' : '7'; ?>">
629 <?php
echo $strTableListOptions; ?
>
632 <fieldset
class="tblFooters">
633 <input type
="submit" name
="modify" value
="<?php echo $strUpdateQuery; ?>" />
636 <td width
="20"> 
;</td
>
639 <legend
><?php
echo sprintf($strQueryOnDb, PMA_getDbLink($db)); ?
>
641 <textarea cols
="80" name
="sql_query" id
="textSqlquery"
642 rows
="<?php echo ($numTableListOptions > 30) ? '15' : '7'; ?>"
643 dir
="<?php echo $text_dir; ?>">
647 if (!isset($qry_select)) {
650 for ($x = 0; $x < $col; $x++
) {
651 if (!empty($curField[$x]) && isset($curShow[$x]) && $curShow[$x] == 'on') {
655 $qry_select .= $curField[$x];
659 if (!empty($qry_select)) {
660 echo 'SELECT ' . htmlspecialchars($qry_select) . "\n";
665 // Create LEFT JOINS out of Relations
666 // Code originally by Mike Beck <mike.beck@ibmiller.de>
667 // If we can use Relations we could make some left joins.
668 // First find out if relations are available in this database.
670 // First we need the really needed Tables - those in TableList might still be
672 if (isset($Field) && count($Field) > 0) {
673 // Initialize some variables
679 $col_where = array();
682 // We only start this if we have fields, otherwise it would be dumb
683 foreach ($Field as $value) {
684 $parts = explode('.', $value);
685 if (!empty($parts[0]) && !empty($parts[1])) {
686 $tab_raw = $parts[0];
687 $tab = str_replace('`', '', $tab_raw);
688 $tab_all[$tab] = $tab;
690 $col_raw = $parts[1];
691 $col_all[] = $tab . '.' . str_replace('`', '', $col_raw);
695 // Check 'where' clauses
696 if ($cfgRelation['relwork'] && count($tab_all) > 0) {
697 // Now we need all tables that we have in the where clause
698 $crit_cnt = count($criteria);
699 for ($x = 0; $x < $crit_cnt; $x++
) {
700 $curr_tab = explode('.', $Field[$x]);
701 if (!empty($curr_tab[0]) && !empty($curr_tab[1])) {
702 $tab_raw = $curr_tab[0];
703 $tab = str_replace('`', '', $tab_raw);
705 $col_raw = $curr_tab[1];
706 $col1 = str_replace('`', '', $col_raw);
707 $col1 = $tab . '.' . $col1;
708 // Now we know that our array has the same numbers as $criteria
709 // we can check which of our columns has a where clause
710 if (!empty($criteria[$x])) {
711 if (substr($criteria[$x], 0, 1) == '=' ||
stristr($criteria[$x], 'is')) {
712 $col_where[$col] = $col1;
713 $tab_wher[$tab] = $tab;
719 // Cleans temp vars w/o further use
724 if (count($tab_wher) == 1) {
725 // If there is exactly one column that has a decent where-clause
726 // we will just use this
727 $master = key($tab_wher);
729 // Now let's find out which of the tables has an index
730 // (When the control user is the same as the normal user
731 // because he is using one of his databases as pmadb,
732 // the last db selected is not always the one where we need to work)
733 PMA_DBI_select_db($db);
735 foreach ($tab_all as $tab) {
736 $ind_rs = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($tab) . ';');
737 while ($ind = PMA_DBI_fetch_assoc($ind_rs)) {
738 $col1 = $tab . '.' . $ind['Column_name'];
739 if (isset($col_all[$col1])) {
740 if ($ind['non_unique'] == 0) {
741 if (isset($col_where[$col1])) {
742 $col_unique[$col1] = 'Y';
744 $col_unique[$col1] = 'N';
747 if (isset($col_where[$col1])) {
748 $col_index[$col1] = 'Y';
750 $col_index[$col1] = 'N';
754 } // end while (each col of tab)
755 } // end while (each tab)
756 // now we want to find the best.
757 if (isset($col_unique) && count($col_unique) > 0) {
758 $col_cand = $col_unique;
760 } elseif (isset($col_index) && count($col_index) > 0) {
761 $col_cand = $col_index;
763 } elseif (isset($col_where) && count($col_where) > 0) {
764 $col_cand = $tab_wher;
767 $col_cand = $tab_all;
771 // If we came up with $col_unique (very good) or $col_index (still
772 // good) as $col_cand we want to check if we have any 'Y' there
773 // (that would mean that they were also found in the whereclauses
774 // which would be great). if yes, we take only those
775 if ($needsort == 1) {
776 foreach ($col_cand as $col => $is_where) {
777 $tab = explode('.', $col);
779 if ($is_where == 'Y') {
787 // Candidates restricted in index+where
790 // None of the candidates where in a where-clause
794 // If our array of candidates has more than one member we'll just
795 // find the smallest table.
796 // Of course the actual query would be faster if we check for
797 // the Criteria which gives the smallest result set in its table,
798 // but it would take too much time to check this
799 if (count($col_cand) > 1) {
800 // Of course we only want to check each table once
801 $checked_tables = $col_cand;
802 foreach ($col_cand as $tab) {
803 if ($checked_tables[$tab] != 1) {
804 $tsize[$tab] = PMA_Table
::countRecords($db, $tab, true, false);
805 $checked_tables[$tab] = 1;
807 $csize[$tab] = $tsize[$tab];
811 $master = key($csize); // Smallest
814 $master = current($col_cand); // Only one single candidate
816 } // end if (exactly one where clause)
818 $tab_left = $tab_all;
819 unset($tab_left[$master]);
820 $tab_know[$master] = $master;
824 while (count($tab_left) > 0) {
826 PMA_getRelatives('master');
828 PMA_getRelatives('foreign');
833 foreach ($tab_left as $tab) {
834 $emerg .= ', ' . PMA_backquote($tab);
835 unset($tab_left[$tab]);
839 $qry_from = PMA_backquote($master) . $emerg . $fromclause;
840 } // end if ($cfgRelation['relwork'] && count($tab_all) > 0)
842 } // end count($Field) > 0
844 // In case relations are not defined, just generate the FROM clause
845 // from the list of tables, however we don't generate any JOIN
847 if (empty($qry_from) && isset($tab_all)) {
848 $qry_from = implode(', ', $tab_all);
850 // Now let's see what we got
851 if (!empty($qry_from)) {
852 echo 'FROM ' . htmlspecialchars($qry_from) . "\n";
858 for ($x = 0; $x < $col; $x++
) {
859 if (!empty($curField[$x]) && !empty($curCriteria[$x]) && $x && isset($last_where) && isset($curAndOrCol)) {
860 $qry_where .= ' ' . strtoupper($curAndOrCol[$last_where]) . ' ';
862 if (!empty($curField[$x]) && !empty($curCriteria[$x])) {
863 $qry_where .= '(' . $curField[$x] . ' ' . $curCriteria[$x] . ')';
868 if ($criteria_cnt > 1) {
869 $qry_where = '(' . $qry_where . ')';
871 // OR rows ${'cur' . $or}[$x]
872 if (!isset($curAndOrRow)) {
873 $curAndOrRow = array();
875 for ($y = 0; $y <= $row; $y++
) {
879 for ($x = 0; $x < $col; $x++
) {
880 if (!empty($curField[$x]) && !empty($
{'curOr' . $y}[$x]) && $x) {
881 $qry_orwhere .= ' ' . strtoupper($curAndOrCol[$last_orwhere]) . ' ';
883 if (!empty($curField[$x]) && !empty($
{'curOr' . $y}[$x])) {
884 $qry_orwhere .= '(' . $curField[$x]
886 . $
{'curOr' . $y}[$x]
892 if ($criteria_cnt > 1) {
893 $qry_orwhere = '(' . $qry_orwhere . ')';
895 if (!empty($qry_orwhere)) {
897 . strtoupper(isset($curAndOrRow[$y]) ?
$curAndOrRow[$y] . ' ' : '')
902 if (!empty($qry_where) && $qry_where != '()') {
903 echo 'WHERE ' . htmlspecialchars($qry_where) . "\n";
909 if (!isset($qry_orderby)) {
912 for ($x = 0; $x < $col; $x++
) {
913 if ($last_orderby && $x && !empty($curField[$x]) && !empty($curSort[$x])) {
914 $qry_orderby .= ', ';
916 if (!empty($curField[$x]) && !empty($curSort[$x])) {
917 // if they have chosen all fields using the * selector,
918 // then sorting is not available
919 // Robbat2 - Fix for Bug #570698
920 if (substr($curField[$x], -2) != '.*') {
921 $qry_orderby .= $curField[$x] . ' ' . $curSort[$x];
926 if (!empty($qry_orderby)) {
927 echo 'ORDER BY ' . htmlspecialchars($qry_orderby) . "\n";
932 <fieldset
class="tblFooters">
933 <input type
="submit" name
="submit_sql" value
="<?php echo $strRunQuery; ?>" />
941 * Displays the footer
943 require_once './libraries/footer.inc.php';