2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * query by example the whole database
12 require_once './libraries/common.inc.php';
15 * Gets the relation settings
17 $cfgRelation = PMA_getRelationsParam();
21 * A query has been submitted -> execute it, else display the headers
23 if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {
25 $zero_rows = htmlspecialchars(__('Your SQL query has been executed successfully'));
30 require './libraries/db_common.inc.php';
31 $url_query .= '&goto=db_qbe.php';
32 $url_params['goto'] = 'db_qbe.php';
33 require './libraries/db_info.inc.php';
36 if (isset($_REQUEST['submit_sql'])
37 && ! preg_match('@^SELECT@i', $sql_query)) {
38 PMA_Message
::warning(__('You have to choose at least one column to display'))->display();
43 * Initialize some variables
45 $col_cnt = PMA_ifSetOr($_REQUEST['col_cnt'], 3, 'numeric');
46 $add_col = PMA_ifSetOr($_REQUEST['add_col'], 0, 'numeric');
47 $add_row = PMA_ifSetOr($_REQUEST['add_row'], 0, 'numeric');
49 $rows = PMA_ifSetOr($_REQUEST['rows'], 0, 'numeric');
50 $ins_col = PMA_ifSetOr($_REQUEST['ins_col'], null, 'array');
51 $del_col = PMA_ifSetOr($_REQUEST['del_col'], null, 'array');
53 $prev_criteria = isset($_REQUEST['prev_criteria'])
54 ?
$_REQUEST['prev_criteria']
56 $criteria = isset($_REQUEST['criteria'])
57 ?
$_REQUEST['criteria']
58 : array_fill(0, $col_cnt, '');
60 $ins_row = isset($_REQUEST['ins_row'])
61 ?
$_REQUEST['ins_row']
62 : array_fill(0, $col_cnt, '');
63 $del_row = isset($_REQUEST['del_row'])
64 ?
$_REQUEST['del_row']
65 : array_fill(0, $col_cnt, '');
66 $and_or_row = isset($_REQUEST['and_or_row'])
67 ?
$_REQUEST['and_or_row']
68 : array_fill(0, $col_cnt, '');
69 $and_or_col = isset($_REQUEST['and_or_col'])
70 ?
$_REQUEST['and_or_col']
71 : array_fill(0, $col_cnt, '');
74 $form_column_width = 12;
75 $col = max($col_cnt +
$add_col, 0);
76 $row = max($rows +
$add_row, 0);
79 // The tables list sent by a previously submitted form
80 if (PMA_isValid($_REQUEST['TableList'], 'array')) {
81 foreach ($_REQUEST['TableList'] as $each_table) {
82 $tbl_names[$each_table] = ' selected="selected"';
87 // this was a work in progress, deactivated for now
88 //$columns = PMA_DBI_get_columns_full($GLOBALS['db']);
89 //$tables = PMA_DBI_get_columns_full($GLOBALS['db']);
95 $tbl_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE
);
96 $tbl_result_cnt = PMA_DBI_num_rows($tbl_result);
97 if (0 == $tbl_result_cnt) {
98 PMA_Message
::error(__('No tables found in database.'))->display();
99 require './libraries/footer.inc.php';
103 // The tables list gets from MySQL
104 while (list($tbl) = PMA_DBI_fetch_row($tbl_result)) {
105 $fld_results = PMA_DBI_get_fields($db, $tbl);
107 if (empty($tbl_names[$tbl]) && !empty($_REQUEST['TableList'])) {
108 $tbl_names[$tbl] = '';
110 $tbl_names[$tbl] = ' selected="selected"';
113 // The fields list per selected tables
114 if ($tbl_names[$tbl] == ' selected="selected"') {
115 $each_table = PMA_backquote($tbl);
116 $fld[] = $each_table . '.*';
117 foreach ($fld_results as $each_field) {
118 $each_field = $each_table . '.' . PMA_backquote($each_field['Field']);
119 $fld[] = $each_field;
121 // increase the width if necessary
122 $form_column_width = max(strlen($each_field), $form_column_width);
126 PMA_DBI_free_result($tbl_result);
128 // largest width found
129 $realwidth = $form_column_width . 'ex';
133 * Displays the Query by example form
137 * Enter description here...
139 * @param array $columns
140 * @param integer $column_number
141 * @param string $selected
143 function showColumnSelectCell($columns, $column_number, $selected = '')
147 <select name
="Field[<?php echo $column_number; ?>]" size
="1">
148 <option value
=""> 
;</option
>
150 foreach ($columns as $column) {
151 if ($column === $selected) {
152 $sel = ' selected="selected"';
156 echo '<option value="' . htmlspecialchars($column) . '"' . $sel . '>'
157 . str_replace(' ', ' ', htmlspecialchars($column)) . '</option>' . "\n";
166 <form action
="db_qbe.php" method
="post">
168 <table
class="data" style
="width: 100%;">
169 <tr
class="odd noclick">
170 <th
><?php
echo __('Column'); ?
>:</th
>
173 for ($x = 0; $x < $col; $x++
) {
174 if (isset($ins_col[$x]) && $ins_col[$x] == 'on') {
175 showColumnSelectCell($fld, $z);
179 if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
184 if (isset($Field[$x])) {
185 $selected = $Field[$x];
186 $curField[$z] = $Field[$x];
188 showColumnSelectCell($fld, $z, $selected);
195 <tr
class="even noclick">
196 <th
><?php
echo __('Sort'); ?
>:</th
>
199 for ($x = 0; $x < $col; $x++
) {
200 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
203 <select style
="width: <?php echo $realwidth; ?>" name
="Sort[<?php echo $z; ?>]" size
="1">
204 <option value
=""> 
;</option
>
205 <option value
="ASC"><?php
echo __('Ascending'); ?
></option
>
206 <option value
="DESC"><?php
echo __('Descending'); ?
></option
>
214 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
219 <select style
="width: <?php echo $realwidth; ?>" name
="Sort[<?php echo $z; ?>]" size
="1">
220 <option value
=""> 
;</option
>
224 // If they have chosen all fields using the * selector,
225 // then sorting is not available
226 // Robbat2 - Fix for Bug #570698
227 if (isset($Sort[$x]) && isset($Field[$x])
228 && substr($Field[$x], -2) == '.*') {
232 if (isset($Sort[$x]) && $Sort[$x] == 'ASC') {
233 $curSort[$z] = $Sort[$x];
234 $sel = ' selected="selected"';
239 echo '<option value="ASC"' . $sel . '>' . __('Ascending') . '</option>' . "\n";
240 if (isset($Sort[$x]) && $Sort[$x] == 'DESC') {
241 $curSort[$z] = $Sort[$x];
242 $sel = ' selected="selected"';
247 echo '<option value="DESC"' . $sel . '>' . __('Descending') . '</option>' . "\n";
259 <tr
class="odd noclick">
260 <th
><?php
echo __('Show'); ?
>:</th
>
263 for ($x = 0; $x < $col; $x++
) {
264 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
267 <input type
="checkbox" name
="Show[<?php echo $z; ?>]" />
274 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
277 if (isset($Show[$x])) {
278 $checked = ' checked="checked"';
279 $curShow[$z] = $Show[$x];
285 <input type
="checkbox" name
="Show[<?php echo $z; ?>]"<?php
echo $checked; ?
> />
294 <!-- Criteria row
-->
295 <tr
class="even noclick">
296 <th
><?php
echo __('Criteria'); ?
>:</th
>
299 for ($x = 0; $x < $col; $x++
) {
300 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
303 <input type
="text" name
="criteria[<?php echo $z; ?>]" value
="" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
310 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
313 if (isset($criteria[$x])) {
314 $tmp_criteria = $criteria[$x];
316 if ((empty($prev_criteria) ||
!isset($prev_criteria[$x]))
317 ||
$prev_criteria[$x] != htmlspecialchars($tmp_criteria)) {
318 $curCriteria[$z] = $tmp_criteria;
320 $curCriteria[$z] = $prev_criteria[$x];
324 <input type
="hidden" name
="prev_criteria[<?php echo $z; ?>]" value
="<?php echo htmlspecialchars($curCriteria[$z]); ?>" />
325 <input type
="text" name
="criteria[<?php echo $z; ?>]" value
="<?php echo htmlspecialchars($tmp_criteria); ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
334 <!-- And/Or columns
and rows
-->
338 for ($y = 0; $y <= $row; $y++
) {
339 if (isset($ins_row[$y]) && $ins_row[$y] == 'on') {
340 $chk['or'] = ' checked="checked"';
343 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">
344 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
345 <!-- Row controls
-->
346 <table cellpadding
="0" cellspacing
="0" border
="0">
348 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
349 <small
><?php
echo __('Ins'); ?
>:</small
>
350 <input type
="checkbox" name
="ins_row[<?php echo $w; ?>]" />
352 <td align
="<?php echo $cell_align_right; ?>">
353 <strong
><?php
echo __('And'); ?
>:</strong
>
356 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
361 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
362 <small
><?php
echo __('Del'); ?
>:</small
>
363 <input type
="checkbox" name
="del_row[<?php echo $w; ?>]" />
365 <td align
="<?php echo $cell_align_right; ?>">
366 <strong
><?php
echo __('Or'); ?
>:</strong
>
369 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
377 for ($x = 0; $x < $col; $x++
) {
378 if (isset($ins_col[$x]) && $ins_col[$x] == 'on') {
380 $or = 'Or' . $w . '[' . $z . ']';
383 <input type
="text" name
="Or<?php echo $or; ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
388 if (isset($del_col[$x]) && $del_col[$x] == 'on') {
393 $or = 'Or' . $w . '[' . $z . ']';
396 <input type
="text" name
="Or<?php echo $or; ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
406 $odd_row =! $odd_row;
409 if (isset($del_row[$y]) && $del_row[$y] == 'on') {
413 if (isset($and_or_row[$y])) {
414 $curAndOrRow[$w] = $and_or_row[$y];
416 if (isset($and_or_row[$y]) && $and_or_row[$y] == 'and') {
417 $chk['and'] = ' checked="checked"';
420 $chk['or'] = ' checked="checked"';
425 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">
426 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
427 <!-- Row controls
-->
428 <table border
="0" cellpadding
="0" cellspacing
="0">
430 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
431 <small
><?php
echo __('Ins'); ?
>:</small
>
432 <input type
="checkbox" name
="ins_row[<?php echo $w; ?>]" />
434 <td align
="<?php echo $cell_align_right; ?>">
435 <strong
><?php
echo __('And'); ?
>:</strong
>
438 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
442 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
443 <small
><?php
echo __('Del'); ?
>:</small
>
444 <input type
="checkbox" name
="del_row[<?php echo $w; ?>]" />
446 <td align
="<?php echo $cell_align_right; ?>">
447 <strong
><?php
echo __('Or'); ?
>:</strong
>
450 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
457 for ($x = 0; $x < $col; $x++
) {
458 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
460 $or = 'Or' . $w . '[' . $z . ']';
463 <input type
="text" name
="Or<?php echo $or; ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
468 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
474 if (!isset($
{$or})) {
477 if (!empty($
{$or}) && isset($
{$or}[$x])) {
478 $tmp_or = $
{$or}[$x];
484 <input type
="text" name
="Or<?php echo $w . '[' . $z . ']'; ?>" value
="<?php echo htmlspecialchars($tmp_or); ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
487 if (!empty($
{$or}) && isset($
{$or}[$x])) {
488 $
{'cur' . $or}[$z] = $
{$or}[$x];
498 $odd_row =! $odd_row;
501 <!-- Modify columns
-->
502 <tr
class="even noclick">
503 <th
><?php
echo __('Modify'); ?
>:</th
>
506 for ($x = 0; $x < $col; $x++
) {
507 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
508 $curAndOrCol[$z] = $and_or_col[$y];
509 if ($and_or_col[$z] == 'or') {
510 $chk['or'] = ' checked="checked"';
513 $chk['and'] = ' checked="checked"';
518 <strong
><?php
echo __('Or'); ?
>:</strong
>
519 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
520  
; 
;<strong
><?php
echo __('And'); ?
>:</strong
>
521 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
523 <?php
echo __('Ins') . "\n"; ?
>
524 <input type
="checkbox" name
="ins_col[<?php echo $z; ?>]" />
525  
; 
;<?php
echo __('Del') . "\n"; ?
>
526 <input type
="checkbox" name
="del_col[<?php echo $z; ?>]" />
533 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
537 if (isset($and_or_col[$y])) {
538 $curAndOrCol[$z] = $and_or_col[$y];
540 if (isset($and_or_col[$z]) && $and_or_col[$z] == 'or') {
541 $chk['or'] = ' checked="checked"';
544 $chk['and'] = ' checked="checked"';
549 <strong
><?php
echo __('Or'); ?
>:</strong
>
550 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
551  
; 
;<strong
><?php
echo __('And'); ?
>:</strong
>
552 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
554 <?php
echo __('Ins') . "\n"; ?
>
555 <input type
="checkbox" name
="ins_col[<?php echo $z; ?>]" />
556  
; 
;<?php
echo __('Del') . "\n"; ?
>
557 <input type
="checkbox" name
="del_col[<?php echo $z; ?>]" />
567 <!-- Other controls
-->
570 $url_params['db'] = $db;
571 $url_params['col_cnt'] = $z;
572 $url_params['rows'] = $w;
573 echo PMA_generate_common_hidden_inputs($url_params);
576 <fieldset
class="tblFooters">
577 <table border
="0" cellpadding
="2" cellspacing
="1">
580 <?php
echo __('Add/Delete criteria rows'); ?
>:
581 <select size
="1" name
="add_row">
582 <option value
="-3">-3</option
>
583 <option value
="-2">-2</option
>
584 <option value
="-1">-1</option
>
585 <option value
="0" selected
="selected">0</option
>
586 <option value
="1">1</option
>
587 <option value
="2">2</option
>
588 <option value
="3">3</option
>
591 <td width
="10"> 
;</td
>
592 <td nowrap
="nowrap"><?php
echo __('Add/Delete columns'); ?
>:
593 <select size
="1" name
="add_col">
594 <option value
="-3">-3</option
>
595 <option value
="-2">-2</option
>
596 <option value
="-1">-1</option
>
597 <option value
="0" selected
="selected">0</option
>
598 <option value
="1">1</option
>
599 <option value
="2">2</option
>
600 <option value
="3">3</option
>
603 <td width
="10"> 
;</td
>
604 <!-- Generates a query
-->
605 <td
><input type
="submit" name
="modify" value
="<?php echo __('Update Query'); ?>" /></td
>
613 <legend
><?php
echo __('Use Tables'); ?
></legend
>
616 $numTableListOptions = 0;
617 foreach ($tbl_names as $key => $val) {
619 $options .= '<option value="' . htmlspecialchars($key) . '"' . $val . '>'
620 . str_replace(' ', ' ', htmlspecialchars($key)) . '</option>' . "\n";
621 $numTableListOptions++
;
624 <select name
="TableList[]" multiple
="multiple" id
="listTable"
625 size
="<?php echo ($numTableListOptions > 30) ? '15' : '7'; ?>">
626 <?php
echo $options; ?
>
629 <fieldset
class="tblFooters">
630 <input type
="submit" name
="modify" value
="<?php echo __('Update Query'); ?>" />
633 <td width
="20"> 
;</td
>
636 <legend
><?php
echo sprintf(__('SQL query on database <b>%s</b>:'), PMA_getDbLink($db)); ?
>
638 <textarea cols
="80" name
="sql_query" id
="textSqlquery"
639 rows
="<?php echo ($numTableListOptions > 30) ? '15' : '7'; ?>"
640 dir
="<?php echo $text_dir; ?>">
644 if (!isset($qry_select)) {
647 for ($x = 0; $x < $col; $x++
) {
648 if (!empty($curField[$x]) && isset($curShow[$x]) && $curShow[$x] == 'on') {
652 $qry_select .= $curField[$x];
656 if (!empty($qry_select)) {
657 echo 'SELECT ' . htmlspecialchars($qry_select) . "\n";
662 // Create LEFT JOINS out of Relations
663 // Code originally by Mike Beck <mike.beck@ibmiller.de>
664 // If we can use Relations we could make some left joins.
665 // First find out if relations are available in this database.
667 // First we need the really needed Tables - those in TableList might still be
669 if (isset($Field) && count($Field) > 0) {
670 // Initialize some variables
676 $col_where = array();
679 // We only start this if we have fields, otherwise it would be dumb
680 foreach ($Field as $value) {
681 $parts = explode('.', $value);
682 if (!empty($parts[0]) && !empty($parts[1])) {
683 $tab_raw = $parts[0];
684 $tab = str_replace('`', '', $tab_raw);
685 $tab_all[$tab] = $tab;
687 $col_raw = $parts[1];
688 $col_all[] = $tab . '.' . str_replace('`', '', $col_raw);
692 // Check 'where' clauses
693 if ($cfgRelation['relwork'] && count($tab_all) > 0) {
694 // Now we need all tables that we have in the where clause
695 $crit_cnt = count($criteria);
696 for ($x = 0; $x < $crit_cnt; $x++
) {
697 $curr_tab = explode('.', $Field[$x]);
698 if (!empty($curr_tab[0]) && !empty($curr_tab[1])) {
699 $tab_raw = $curr_tab[0];
700 $tab = str_replace('`', '', $tab_raw);
702 $col_raw = $curr_tab[1];
703 $col1 = str_replace('`', '', $col_raw);
704 $col1 = $tab . '.' . $col1;
705 // Now we know that our array has the same numbers as $criteria
706 // we can check which of our columns has a where clause
707 if (!empty($criteria[$x])) {
708 if (substr($criteria[$x], 0, 1) == '=' ||
stristr($criteria[$x], 'is')) {
709 $col_where[$col] = $col1;
710 $tab_wher[$tab] = $tab;
716 // Cleans temp vars w/o further use
721 if (count($tab_wher) == 1) {
722 // If there is exactly one column that has a decent where-clause
723 // we will just use this
724 $master = key($tab_wher);
726 // Now let's find out which of the tables has an index
727 // (When the control user is the same as the normal user
728 // because he is using one of his databases as pmadb,
729 // the last db selected is not always the one where we need to work)
730 PMA_DBI_select_db($db);
732 foreach ($tab_all as $tab) {
733 $ind_rs = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($tab) . ';');
734 while ($ind = PMA_DBI_fetch_assoc($ind_rs)) {
735 $col1 = $tab . '.' . $ind['Column_name'];
736 if (isset($col_all[$col1])) {
737 if ($ind['non_unique'] == 0) {
738 if (isset($col_where[$col1])) {
739 $col_unique[$col1] = 'Y';
741 $col_unique[$col1] = 'N';
744 if (isset($col_where[$col1])) {
745 $col_index[$col1] = 'Y';
747 $col_index[$col1] = 'N';
751 } // end while (each col of tab)
752 } // end while (each tab)
753 // now we want to find the best.
754 if (isset($col_unique) && count($col_unique) > 0) {
755 $col_cand = $col_unique;
757 } elseif (isset($col_index) && count($col_index) > 0) {
758 $col_cand = $col_index;
760 } elseif (isset($col_where) && count($col_where) > 0) {
761 $col_cand = $tab_wher;
764 $col_cand = $tab_all;
768 // If we came up with $col_unique (very good) or $col_index (still
769 // good) as $col_cand we want to check if we have any 'Y' there
770 // (that would mean that they were also found in the whereclauses
771 // which would be great). if yes, we take only those
772 if ($needsort == 1) {
773 foreach ($col_cand as $col => $is_where) {
774 $tab = explode('.', $col);
776 if ($is_where == 'Y') {
784 // Candidates restricted in index+where
787 // None of the candidates where in a where-clause
791 // If our array of candidates has more than one member we'll just
792 // find the smallest table.
793 // Of course the actual query would be faster if we check for
794 // the Criteria which gives the smallest result set in its table,
795 // but it would take too much time to check this
796 if (count($col_cand) > 1) {
797 // Of course we only want to check each table once
798 $checked_tables = $col_cand;
799 foreach ($col_cand as $tab) {
800 if ($checked_tables[$tab] != 1) {
801 $tsize[$tab] = PMA_Table
::countRecords($db, $tab, false);
802 $checked_tables[$tab] = 1;
804 $csize[$tab] = $tsize[$tab];
808 $master = key($csize); // Smallest
811 $master = current($col_cand); // Only one single candidate
813 } // end if (exactly one where clause)
815 $tab_left = $tab_all;
816 unset($tab_left[$master]);
817 $tab_know[$master] = $master;
821 while (count($tab_left) > 0) {
823 PMA_getRelatives('master');
825 PMA_getRelatives('foreign');
830 foreach ($tab_left as $tab) {
831 $emerg .= ', ' . PMA_backquote($tab);
832 unset($tab_left[$tab]);
836 $qry_from = PMA_backquote($master) . $emerg . $fromclause;
837 } // end if ($cfgRelation['relwork'] && count($tab_all) > 0)
839 } // end count($Field) > 0
841 // In case relations are not defined, just generate the FROM clause
842 // from the list of tables, however we don't generate any JOIN
844 if (empty($qry_from) && isset($tab_all)) {
845 $qry_from = implode(', ', $tab_all);
847 // Now let's see what we got
848 if (!empty($qry_from)) {
849 echo 'FROM ' . htmlspecialchars($qry_from) . "\n";
855 for ($x = 0; $x < $col; $x++
) {
856 if (!empty($curField[$x]) && !empty($curCriteria[$x]) && $x && isset($last_where) && isset($curAndOrCol)) {
857 $qry_where .= ' ' . strtoupper($curAndOrCol[$last_where]) . ' ';
859 if (!empty($curField[$x]) && !empty($curCriteria[$x])) {
860 $qry_where .= '(' . $curField[$x] . ' ' . $curCriteria[$x] . ')';
865 if ($criteria_cnt > 1) {
866 $qry_where = '(' . $qry_where . ')';
868 // OR rows ${'cur' . $or}[$x]
869 if (!isset($curAndOrRow)) {
870 $curAndOrRow = array();
872 for ($y = 0; $y <= $row; $y++
) {
876 for ($x = 0; $x < $col; $x++
) {
877 if (!empty($curField[$x]) && !empty($
{'curOr' . $y}[$x]) && $x) {
878 $qry_orwhere .= ' ' . strtoupper($curAndOrCol[$last_orwhere]) . ' ';
880 if (!empty($curField[$x]) && !empty($
{'curOr' . $y}[$x])) {
881 $qry_orwhere .= '(' . $curField[$x]
883 . $
{'curOr' . $y}[$x]
889 if ($criteria_cnt > 1) {
890 $qry_orwhere = '(' . $qry_orwhere . ')';
892 if (!empty($qry_orwhere)) {
894 . strtoupper(isset($curAndOrRow[$y]) ?
$curAndOrRow[$y] . ' ' : '')
899 if (!empty($qry_where) && $qry_where != '()') {
900 echo 'WHERE ' . htmlspecialchars($qry_where) . "\n";
906 if (!isset($qry_orderby)) {
909 for ($x = 0; $x < $col; $x++
) {
910 if ($last_orderby && $x && !empty($curField[$x]) && !empty($curSort[$x])) {
911 $qry_orderby .= ', ';
913 if (!empty($curField[$x]) && !empty($curSort[$x])) {
914 // if they have chosen all fields using the * selector,
915 // then sorting is not available
916 // Robbat2 - Fix for Bug #570698
917 if (substr($curField[$x], -2) != '.*') {
918 $qry_orderby .= $curField[$x] . ' ' . $curSort[$x];
923 if (!empty($qry_orderby)) {
924 echo 'ORDER BY ' . htmlspecialchars($qry_orderby) . "\n";
929 <fieldset
class="tblFooters">
930 <input type
="submit" name
="submit_sql" value
="<?php echo __('Submit Query'); ?>" />
938 * Displays the footer
940 require './libraries/footer.inc.php';