Order, limit
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@55 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
3a5eda55b3
commit
fbcf6fb464
|
@ -3,26 +3,24 @@ $indexes = indexes($_GET["select"]);
|
||||||
page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]));
|
page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]));
|
||||||
|
|
||||||
echo '<p><a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '">' . lang('New item') . "</a></p>\n";
|
echo '<p><a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '">' . lang('New item') . "</a></p>\n";
|
||||||
echo "<form action='' id='form'><div>\n";
|
echo "<form action='' id='form'>\n<fieldset><legend>" . lang('Search') . "</legend>\n";
|
||||||
if (strlen($_GET["server"])) {
|
if (strlen($_GET["server"])) {
|
||||||
echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '" />';
|
echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '" />';
|
||||||
}
|
}
|
||||||
echo '<input type="hidden" name="db" value="' . htmlspecialchars($_GET["db"]) . '" />';
|
echo '<input type="hidden" name="db" value="' . htmlspecialchars($_GET["db"]) . '" />';
|
||||||
echo '<input type="hidden" name="select" value="' . htmlspecialchars($_GET["select"]) . '" />';
|
echo '<input type="hidden" name="select" value="' . htmlspecialchars($_GET["select"]) . '" />';
|
||||||
|
echo "\n";
|
||||||
|
|
||||||
$where = array();
|
$where = array();
|
||||||
$columns = array();
|
$columns = array_keys(fields($_GET["select"]));
|
||||||
foreach (fields($_GET["select"]) as $name => $field) {
|
|
||||||
$columns[] = $name;
|
|
||||||
}
|
|
||||||
$operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IS NULL");
|
$operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IS NULL");
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ((array) $_GET["where"] as $val) {
|
foreach ((array) $_GET["where"] as $val) {
|
||||||
if ($val["col"] && in_array($val["op"], $operators)) {
|
if ($val["col"] && in_array($val["op"], $operators)) {
|
||||||
$where[] = idf_escape($val["col"]) . " $val[op]" . ($val["op"] != "IS NULL" ? " '" . mysql_real_escape_string($val["val"]) . "'" : "");
|
$where[] = idf_escape($val["col"]) . " $val[op]" . ($val["op"] != "IS NULL" ? " '" . mysql_real_escape_string($val["val"]) . "'" : "");
|
||||||
echo "<select name='where[$i][col]'><option></option>" . optionlist($columns, $val["col"], "not_vals") . "</select>";
|
echo "<div><select name='where[$i][col]'><option></option>" . optionlist($columns, $val["col"], "not_vals") . "</select>";
|
||||||
echo "<select name='where[$i][op]' onchange=\"where_change(this);\">" . optionlist($operators, $val["op"], "not_vals") . "</select>";
|
echo "<select name='where[$i][op]' onchange=\"where_change(this);\">" . optionlist($operators, $val["op"], "not_vals") . "</select>";
|
||||||
echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . "\" /><br />\n";
|
echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . "\" /></div>\n";
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,21 +30,44 @@ function where_change(op) {
|
||||||
op.form[op.name.substr(0, op.name.length - 4) + '[val]'].style.display = (op.value == 'IS NULL' ? 'none' : '');
|
op.form[op.name.substr(0, op.name.length - 4) + '[val]'].style.display = (op.value == 'IS NULL' ? 'none' : '');
|
||||||
}
|
}
|
||||||
<?php if ($i) { ?>
|
<?php if ($i) { ?>
|
||||||
for (var i=0; <?php echo $i; ?> > i; i++) document.getElementById('form')['where[' + i + '][op]'].onchange();
|
for (var i=0; <?php echo $i; ?> > i; i++) {
|
||||||
|
document.getElementById('form')['where[' + i + '][op]'].onchange();
|
||||||
|
}
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
echo "<select name='where[$i][col]'><option></option>" . optionlist($columns, array(), "not_vals") . "</select>";
|
echo "<div><select name='where[$i][col]'><option></option>" . optionlist($columns, array(), "not_vals") . "</select>";
|
||||||
echo "<select name='where[$i][op]' onchange=\"where_change(this);\">" . optionlist($operators, array(), "not_vals") . "</select>";
|
echo "<select name='where[$i][op]' onchange=\"where_change(this);\">" . optionlist($operators, array(), "not_vals") . "</select>";
|
||||||
echo "<input name='where[$i][val]' /><br />\n"; //! JavaScript for adding next
|
echo "<input name='where[$i][val]' /></div>\n"; //! JavaScript for adding next
|
||||||
//! fulltext search
|
//! fulltext search
|
||||||
|
echo "</fieldset>\n";
|
||||||
|
|
||||||
//! sort, limit
|
echo "<fieldset><legend>" . lang('Order by') . "</legend>\n";
|
||||||
$limit = 30;
|
$order = array();
|
||||||
|
$i = 0;
|
||||||
|
foreach ((array) $_GET["order"] as $key => $val) {
|
||||||
|
if (in_array($val, $columns, true)) {
|
||||||
|
$desc = in_array($key, (array) $_GET["desc"]);
|
||||||
|
$order[] = idf_escape($val) . ($desc ? " DESC" : "");
|
||||||
|
echo "<div><select name='order[$i]'><option></option>" . optionlist($columns, $val, "not_vals") . "</select>";
|
||||||
|
echo "<input type='checkbox' name='desc[]' value='$i' id='desc-$i'" . ($desc ? " checked='checked'" : "") . " /><label for='desc-$i'>" . lang('DESC') . "</label></div>\n";
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo "<div><select name='order[$i]'><option></option>" . optionlist($columns, array(), "not_vals") . "</select>";
|
||||||
|
echo "<input type='checkbox' name='desc[$i]' value='1' id='desc-$i' /><label for='desc-$i'>" . lang('DESC') . "</label></div>\n";
|
||||||
|
echo "</fieldset>\n";
|
||||||
|
|
||||||
echo "<input type='submit' value='" . lang('Search') . "' />\n";
|
echo "<fieldset><legend>" . lang('Limit') . "</legend>\n";
|
||||||
echo "</div></form>\n";
|
$limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30");
|
||||||
$result = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . " LIMIT $limit OFFSET " . ($limit * $_GET["page"]));
|
echo '<div><input name="limit" size="3" value="' . htmlspecialchars($limit) . '" /></div>';
|
||||||
|
echo "</fieldset>\n";
|
||||||
|
|
||||||
|
echo "<fieldset><legend>" . lang('Action') . "</legend><div><input type='submit' value='" . lang('Select') . "' /></div></fieldset>\n";
|
||||||
|
echo "</form>\n";
|
||||||
|
echo "<div style='clear: left; margin-bottom: 1em;'></div>\n";
|
||||||
|
|
||||||
|
$result = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . " OFFSET " . ($limit * $_GET["page"]) : ""));
|
||||||
$found_rows = mysql_result(mysql_query(" SELECT FOUND_ROWS()"), 0); // space for mysql.trace_mode
|
$found_rows = mysql_result(mysql_query(" SELECT FOUND_ROWS()"), 0); // space for mysql.trace_mode
|
||||||
if (!mysql_num_rows($result)) {
|
if (!mysql_num_rows($result)) {
|
||||||
echo "<p class='message'>" . lang('No rows.') . "</p>\n";
|
echo "<p class='message'>" . lang('No rows.') . "</p>\n";
|
||||||
|
@ -98,10 +119,10 @@ if (!mysql_num_rows($result)) {
|
||||||
echo "</tr>\n";
|
echo "</tr>\n";
|
||||||
}
|
}
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
if ($found_rows > $limit) {
|
if (intval($limit) && $found_rows > $limit) {
|
||||||
echo "<p>" . lang('Page') . ":\n";
|
echo "<p>" . lang('Page') . ":\n";
|
||||||
for ($i=0; $i < $found_rows / $limit; $i++) {
|
for ($i=0; $i < $found_rows / $limit; $i++) {
|
||||||
echo ($i == $_GET["page"] ? $i + 1 : '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($_GET['select']) . ($i ? "&page=$i" : "") . '">' . ($i + 1) . "</a>") . "\n";
|
echo ($i == $_GET["page"] ? $i + 1 : '<a href="' . htmlspecialchars(preg_replace('~(\\?)page=[^&]*&|&page=[^&]*~', '\\1', $_SERVER["REQUEST_URI"]) . ($i ? "&page=$i" : "")) . '">' . ($i + 1) . "</a>") . "\n";
|
||||||
}
|
}
|
||||||
echo "</p>\n";
|
echo "</p>\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue