6 * Gets some core libraries
8 require('./libraries/grab_globals.lib.php3');
9 require('./libraries/common.lib.php3');
10 require('./libraries/relation.lib.php3'); // foreign keys
14 * Defines arrays of functions (should possibly be in config.inc.php3
15 * so it can also be used in tbl_qbe.php3)
17 $numfunctions = array('=', '>', '>=', '<', '<=', '!=');
18 $textfunctions = array('LIKE', '=', '!=');
22 * Not selection yet required -> displays the selection form
24 if (!isset($param) ||
$param[0] == '') {
25 // Gets some core libraries
26 include('./tbl_properties_common.php3');
27 $err_url = 'tbl_select.php3' . $err_url;
28 $url_query .= '&goto=tbl_select.php3&back=tbl_select.php3';
29 include('./tbl_properties_table_info.php3');
31 // Defines the url to return to in case of error in the next sql statement
34 . '&convcharset=' . $convcharset
35 . '&server=' . $server
36 . '&db=' . urlencode($db)
37 . '&table=' . urlencode($table);
39 // Gets the list and number of fields
40 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
41 $result = @PMA_mysql_query
($local_query);
43 PMA_mysqlDie('', $local_query, '', $err_url);
46 $fields_cnt = mysql_num_rows($result);
47 while ($row = PMA_mysql_fetch_array($result)) {
48 $fields_list[] = $row['Field'];
50 // reformat mysql query output - staybyte - 9. June 2001
51 $shorttype = substr($type, 0, 3);
52 if ($shorttype == 'set' ||
$shorttype == 'enu') {
53 $type = eregi_replace(',', ', ', $type);
54 // Removes automatic MySQL escape format
55 $type = str_replace('\'\'', '\\\'', $type);
57 $type = eregi_replace('BINARY', '', $type);
58 $type = eregi_replace('ZEROFILL', '', $type);
59 $type = eregi_replace('UNSIGNED', '', $type);
63 $fields_type[] = $type;
65 mysql_free_result($result);
68 // retrieve keys into foreign fields, if any
69 $cfgRelation = PMA_getRelationsParam();
70 $foreigners = ($cfgRelation['relwork'] ?
PMA_getForeigners($db, $table) : FALSE);
72 <form method
="post" action
="tbl_select.php3">
73 <input type
="hidden" name
="server" value
="<?php echo $server; ?>" />
74 <input type
="hidden" name
="lang" value
="<?php echo $lang; ?>" />
75 <input type
="hidden" name
="convcharset" value
="<?php echo $convcharset; ?>" />
76 <input type
="hidden" name
="db" value
="<?php echo $db; ?>" />
77 <input type
="hidden" name
="table" value
="<?php echo $table; ?>" />
78 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
79 <input type
="hidden" name
="back" value
="tbl_select.php3" />
80  
; 
; 
; 
; 
;
81 <?php
echo $strSelectFields; ?
> 
;:<br
/>
82  
; 
; 
; 
; 
;
83 <select name
="param[]" size
="<?php echo ($fields_cnt < 10) ? $fields_cnt : 10; ?>" multiple
="multiple">
86 // Displays the list of the fields
87 for ($i = 0 ; $i < $fields_cnt; $i++
) {
88 echo ' <option value="' . urlencode($fields_list[$i]) . '" selected="selected">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
94 <div style
="margin-bottom: 10px">
95 <?php
echo $strLimitNumRows . "\n"; ?
>
96 <input type
="text" size
="4" name
="session_max_rows" value
="<?php echo $cfg['MaxRows']; ?>" class="textfield" />
100 <?php
echo $strAddSearchConditions; ?
><br
/>
101 <input type
="text" name
="where" class="textfield" /> 
;
102 <?php
echo PMA_showMySQLDocu('Reference', 'Functions') . "\n"; ?
>
104 <?php
echo '<i>' . $strOr . '</i> ' . $strDoAQuery; ?
><br
/>
105 <table border
="<?php echo $cfg['Border']; ?>">
107 <th
><?php
echo $strField; ?
></th
>
108 <th
><?php
echo $strType; ?
></th
>
109 <th
><?php
echo $strFunction; ?
></th
>
110 <th
><?php
echo $strValue; ?
></th
>
113 for ($i = 0; $i < $fields_cnt; $i++
) {
115 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
118 <td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo htmlspecialchars($fields_list[$i]); ?
></td
>
119 <td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo $fields_type[$i]; ?
></td
>
120 <td bgcolor
="<?php echo $bgcolor; ?>">
121 <select name
="func[]">
123 reset($numfunctions);
124 reset($textfunctions);
125 if (eregi('char|blob|text|set|enum', $fields_type[$i])) {
126 while (list($k, $fc) = each($textfunctions)) {
128 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
131 while (list($k, $fc) = each($numfunctions)) {
133 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
135 } // end if... else...
140 <td bgcolor
="<?php echo $bgcolor; ?>">
143 $field = $fields_list[$i];
145 include('./libraries/get_foreign.lib.php3');
148 if ($foreigners && isset($foreigners[$field]) && isset($disp) && $disp) {
149 echo ' <select name="fields[]">' . "\n";
150 echo ' <option value=""></option>' . "\n";
151 while ($relrow = @PMA_mysql_fetch_array
($disp)) {
152 $key = $relrow[$foreign_field];
153 $value = (($foreign_display != FALSE) ?
'-' . htmlspecialchars($relrow[$foreign_display]) : '');
154 echo ' <option value="' . urlencode($key) . '">'
155 . htmlspecialchars($key) . $value . '</option>' . "\n";
157 echo ' </select>' . "\n";
159 echo ' <input type="text" name="fields[]" size="40" class="textfield" />' . "\n";
162 <input type
="hidden" name
="names[]" value
="<?php echo urlencode($fields_list[$i]); ?>" />
163 <input type
="hidden" name
="types[]" value
="<?php echo $fields_type[$i]; ?>" />
173 <?php
echo $strDisplayOrder; ?
><br
/>
174 <select name
="orderField" style
="vertical-align: middle">
175 <option value
="--nil--"></option
>
178 for ($i = 0; $i < $fields_cnt; $i++
) {
180 echo '<option value="' . urlencode($fields_list[$i]) . '">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
184 <input type
="radio" name
="order" value
="ASC" checked
="checked" />
185 <?php
echo $strAscending; ?
> 
;
186 <input type
="radio" name
="order" value
="DESC" />
187 <?php
echo $strDescending; ?
><br
/><br
/>
191  
; 
; 
; 
;
192 <input type
="submit" name
="submit" value
="<?php echo $strGo; ?>" />
197 include('./footer.inc.php3');
202 * Selection criteria have been submitted -> do the work
206 $sql_query = 'SELECT ' . PMA_backquote(urldecode($param[0]));
211 $sql_query .= ',' . PMA_backquote(urldecode($param[$i]));
215 $sql_query .= ' FROM ' . PMA_backquote($table);
218 $sql_query .= ' WHERE ' . ((get_magic_quotes_gpc()) ?
stripslashes($where) : $where);
221 $sql_query .= ' WHERE 1';
222 for ($i = 0; $i < count($fields); $i++
) {
223 if (!empty($fields) && $fields[$i] != '') {
224 if (eregi('char|blob|text|set|enum|date|time|year', $types[$i])) {
229 if (strtoupper($fields[$i]) == 'NULL' ||
strtoupper($fields[$i]) == 'NOT NULL') {
233 $sql_query .= ' AND ' . PMA_backquote(urldecode($names[$i])) . " $func[$i] $quot$fields[$i]$quot";
238 if ($orderField != '--nil--') {
239 $sql_query .= ' ORDER BY ' . PMA_backquote(urldecode($orderField)) . ' ' . $order;
242 // The query will be stripslashed in sql.php3 if "magic_quotes_gpc" is on
243 if (get_magic_quotes_gpc()) {
244 $sql_query = addslashes($sql_query);
246 include('./sql.php3');