Gumbo
Erfahrenes Mitglied
Folgendes Skript listet den gesamten Inhalt einer Tabelle samt Betitelung auf:
PHP:
<?php
include 'connect.inc.php';
$table = 'Links';
$fileds = array();
$query = '
SHOW
COLUMNS
FROM
`'.$table.'`
';
if( !$result = mysql_query($query) ) {
echo '<p><strong>MySQL Error <tt>'.mysql_errno().'</tt>:</strong> '.htmlspecialchars(mysql_error()).'<pre>'.$query.'</pre></p>';
exit;
}
echo '<table><thead><tr>';
while( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) {
echo '<th>'.$row['Field'].'</th>';
$fields[] = $row['Field'];
}
echo '</tr></thead>';
$query = '
SELECT';
$field = current($fields);
do {
$query .= sprintf('%c `%s`', 10, $field);
if( $field = next($fields) ) {
$query .= ',';
}
} while( $field );
$query .= '
FROM
`'.$table.'`
';
if( !$result = mysql_query($query) ) {
echo '<p><strong>MySQL Error <tt>'.mysql_errno().'</tt>:</strong> '.htmlspecialchars(mysql_error()).'<pre>'.$query.'</pre></p>';
exit;
}
echo '<tbody>';
while( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) {
echo '<tr>';
foreach( $row as $field ) {
echo '<td>'.htmlentities($field).'</td>';
}
echo '</tr>';
}
echo '</tbody></table>';
?>
Zuletzt bearbeitet: