| Index
» Projekty
» phpMyEdit
» Fórum
» Just a litte thing |
 |
sirozz
Založený: 29.01.2009
Príspevky: 1
Zaslal: 2009-01-29 11:06
Návrat hore
Odpovedať s citátom
|
Sorry for bad english...
Here is a little php script derived from the setup to automatically create fields:
file autofields.php:
| Kód: |
<?php
$skip = !isset ( $skip ) ? 0 : $skip;
@mysql_select_db($opts['db']);
$tb_desc = @mysql_query("DESCRIBE $tb");
$fds = @mysql_list_fields($opts['db'], $opts['tb']);
$num_fds = @mysql_num_fields($fds);
$ts_cnt = 0;
for ($k = 0; $k < $num_fds; $k++) {
if ( $k < $skip ) continue;
$fd = mysql_field_name($fds,$k);
$fm = mysql_fetch_field($fds,$k);
$fn = strtr($fd, '_-.', ' ');
$fn = preg_replace('/(^| +)id( +|$)/', '\\1ID\\2', $fn); // uppercase IDs
$fn = ucfirst($fn);
$row = @mysql_fetch_array($tb_desc);
$opts['fdd'][$fd]['name'] = str_replace ('\'','\\\'',$fn);
$auto_increment = strstr($row[5], 'auto_increment') ? 1 : 0;
if (substr($row[1],0,3) == 'set') {
$opts['fdd'][$fd]['select'] = 'M';
} else {
$opts['fdd'][$fd]['select'] = 'T';
}
if ($auto_increment) {
$opts['fdd'][$fd]['options'] = 'AVCPDR';
}
// timestamps are read-only
else if (@mysql_field_type($fds, $k) == 'timestamp') {
if ($ts_cnt > 0) {
$opts['fdd'][$fd]['options'] = 'AVCPD';
} else { // first timestamp
$opts['fdd'][$fd]['options'] = 'AVCPDR';
}
$ts_cnt++;
}
$opts['fdd'][$fd]['maxlen'] = @mysql_field_len($fds,$k);
// blobs -> textarea
if (@mysql_field_type($fds,$k) == 'blob') {
$opts['fdd'][$fd]['textarea'] = array ( 'rows' => 5, 'cols' => 50 );
}
// SETs and ENUMs get special treatment
if ((substr($row[1],0,3) == 'set' || substr($row[1],0,4) == 'enum')
&& ! (($pos = strpos($row[1], '(')) === false)) {
$indent = str_repeat(' ', 18);
$outstr = substr($row[1], $pos + 2, -2);
$outstr = explode("','", $outstr);
$outstr = str_replace("''", "'", $outstr);
$outstr = str_replace('"', '\\"', $outstr);
$outstr = implode('",'.PHP_EOL.$indent.'"', $outstr);
$opts['fdd'][$fd]['values'] = array( PHP_EOL . $indent . '"' . $outstr );
}
// automatic support for Default values
if ($row[4] != '' && $row[4] != 'NULL') {
$opts['fdd'][$fd]['default'] = $row[4];
} else if ($auto_increment) {
$opts['fdd'][$fd]['default'] = 0;
}
$opts['fdd'][$fd]['sort'] = true;
}
?>
|
And now you can...
| Kód: |
$skip = 3;
include "autofields.php";
|
instead...
| Kód: |
$opts['fdd']['id'] = array(
'name' => 'ID',
'select' => 'T',
'options' => 'AVCPDR', // auto increment
'maxlen' => 11
...
|
|
iomas
Založený: 03.07.2008
Príspevky: 6
Zaslal: 2009-04-30 07:18
Návrat hore
Odpovedať s citátom
|
can you please explain a little more!
|
|
Odoslať novú tému
Odpovedať na tému
|
|
|
|