php通用显示mysql库数据表方法
php通用显示mysql库数据表方法 php通用显示mysql库数据表方法:```{.php}lt;?phpinclude #39;file/for/database/connection.php#39;;function displayTable($query = quot;quot;){ $table = #39;#39;; $sql = mysql_query($query);
php通用显示mysql库数据表方法:
<?php include 'file/for/database/connection.php'; function displayTable($query = ""){ $table = ''; $sql = mysql_query($query); $table .= '<table>'; $table .= '<tr>'; while($field = mysql_fetch_field($sql)){ $table .= '<th>'.$field->name.'</th>'; } $table .= '</tr>'; while($row = mysql_fetch_assoc($sql)){ $table .= '<tr>'; foreach($row as $key => $item){ $table .= '<td style="padding-right:50px;">'.htmlentities($item).'</td>'; } $table .= '</tr>'; } $table .= '</table>'; return $table; } echo displayTable("SELECT * FROM users"); // Displays all rows in the table echo displayTable("SELECT username, email FROM users"); // displays only username and email in the table ?>
精彩图集
精彩文章