num_rows) {
echo "
" . lang('No rows.') . "\n";
} else {
echo "
\n";
$links = array(); // colno => orgtable - create links from these columns
$indexes = array(); // orgtable => array(column => colno) - primary keys
$columns = array(); // orgtable => array(column => ) - not selected columns in primary key
$blobs = array(); // colno => bool - display bytes for blobs
$types = array(); // colno => type - display char in
odd(''); // reset odd for each result
for ($i=0; $row = $result->fetch_row(); $i++) {
if (!$i) {
echo "";
for ($j=0; $j < count($row); $j++) {
$field = $result->fetch_field();
$orgtable = $field->orgtable;
$orgname = $field->orgname;
if ($orgtable != "") {
if (!isset($indexes[$orgtable])) {
// find primary key in each table
$indexes[$orgtable] = array();
foreach (indexes($orgtable, $connection2) as $index) {
if ($index["type"] == "PRIMARY") {
$indexes[$orgtable] = array_flip($index["columns"]);
break;
}
}
$columns[$orgtable] = $indexes[$orgtable];
}
if (isset($columns[$orgtable][$orgname])) {
unset($columns[$orgtable][$orgname]);
$indexes[$orgtable][$orgname] = $j;
$links[$j] = $orgtable;
}
}
if ($field->charsetnr == 63) { // 63 - binary
$blobs[$j] = true;
}
$types[$j] = $field->type;
echo "name != $orgname ? " title='" . h(($orgtable != "" ? "$orgtable." : "") . $orgname) . "'" : "") . ">" . h($field->name);
}
echo " |
\n";
}
echo "";
foreach ($row as $key => $val) {
if (!isset($val)) {
$val = "NULL";
} else {
if ($blobs[$key] && !is_utf8($val)) {
$val = "" . lang('%d byte(s)', strlen($val)) . ""; //! link to download
} elseif (!strlen($val)) { // strlen - SQLite can return int
$val = " "; // some content to print a border
} else {
$val = h($val);
if ($types[$key] == 254) { // 254 - char
$val = "$val
";
}
}
if (isset($links[$key]) && !$columns[$links[$key]]) {
$link = "edit=" . urlencode($links[$key]);
foreach ($indexes[$links[$key]] as $col => $j) {
$link .= "&where" . urlencode("[" . bracket_escape($col) . "]") . "=" . urlencode($row[$j]);
}
$val = "$val";
}
}
echo "$val";
}
}
echo " |
\n";
}
}
/** Get referencable tables with single column primary key except self
* @param string
* @return array ($table_name => $field)
*/
function referencable_primary($self) {
$return = array(); // table_name => field
foreach (table_status() as $table_name => $table) {
if ($table_name != $self && fk_support($table)) {
foreach (fields($table_name) as $field) {
if ($field["primary"]) {
if ($return[$table_name]) { // multi column primary key
unset($return[$table_name]);
break;
}
$return[$table_name] = $field;
}
}
}
}
return $return;
}
/** Print table columns for type edit
* @param string
* @param array
* @param array
* @param array returned by referencable_primary()
* @return null
*/
function edit_type($key, $field, $collations, $foreign_keys = array()) {
global $structured_types, $types, $unsigned, $inout, $on_actions;
?>
| " size="3" onfocus="editingLengthFocus(this);"> | |