$return = array();
$result = mysql_query("SHOW INDEX FROM " . idf_escape($table));
while ($row = mysql_fetch_assoc($result)) {
- $type = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
- $return[$type][$row["Key_name"]][$row["Seq_in_index"]] = $row["Column_name"];
+ $return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
+ $return[$row["Key_name"]]["columns"][$row["Seq_in_index"]] = $row["Column_name"];
}
mysql_free_result($result);
return $return;
}
function unique_idf($row, $indexes) {
- foreach ($indexes as $type => $index) {
- if ($type == "PRIMARY" || $type == "UNIQUE") {
- foreach ($index as $columns) {
- $return = array();
- foreach ($columns as $key) {
- if (!isset($row[$key])) {
- continue 2;
- }
- $return[] = urlencode("where[$key]") . "=" . urlencode($row[$key]);
+ foreach ($indexes as $index) {
+ if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") {
+ $return = array();
+ foreach ($index["columns"] as $key) {
+ if (!isset($row[$key])) {
+ continue 2;
}
- return $return;
+ $return[] = urlencode("where[$key]") . "=" . urlencode($row[$key]);
}
+ return $return;
}
}
$return = array();
<?php
$fields = array_keys(fields($_GET["indexes"]));
$j = 0;
-foreach ($row["indexes"] as $type => $index) {
- foreach ($index as $columns) {
- echo "<tr><td><select name='indexes[$j][type]'><option></option>" . optionlist($index_types, $type, "not_vals") . "</select></td><td>";
- sort($columns);
- foreach ($columns as $i => $column) {
- echo "<select name='indexes[$j][columns][$i]'><option></option>" . optionlist($fields, $column, "not_vals") . "</select>";
- }
- echo "<select name='indexes[$j][columns][" . ($i+1) . "]'><option></option>" . optionlist($fields, array(), "not_vals") . "</select>";
- echo "</td></tr>\n";
- $j++;
+foreach ($row["indexes"] as $index) {
+ echo "<tr><td><select name='indexes[$j][type]'><option></option>" . optionlist($index_types, $index["type"], "not_vals") . "</select></td><td>";
+ sort($index["columns"]);
+ foreach ($index["columns"] as $i => $column) {
+ echo "<select name='indexes[$j][columns][$i]'><option></option>" . optionlist($fields, $column, "not_vals") . "</select>";
}
+ echo "<select name='indexes[$j][columns][" . ($i+1) . "]'><option></option>" . optionlist($fields, array(), "not_vals") . "</select>";
+ echo "</td></tr>\n";
+ $j++;
}
//! JavaScript for adding more indexes and columns
?>
$indexes = indexes($_GET["table"]);
if ($indexes) {
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
- foreach ($indexes as $type => $index) {
- foreach ($index as $columns) {
- sort($columns);
- echo "<tr><td>$type</td><td><i>" . implode("</i>, <i>", $columns) . "</i></td></tr>\n";
- }
+ foreach ($indexes as $index) {
+ sort($index["columns"]);
+ echo "<tr><td>$index[type]</td><td><i>" . implode("</i>, <i>", $index["columns"]) . "</i></td></tr>\n";
}
echo "</table>\n";
}