企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
format the output for an HTML table. ~~~ <?php print('<table cols="6"><th>Table</th><th>Data Size</th><th>Index Size</th><th>Total size</th><th>Total Rows</th><th>Avg. Size per Row</th>'); mysql_connect("localhost","my_user","password"); $result = mysql_query("SHOW TABLE STATUS FROM test;"); while($array = mysql_fetch_array($result)) { $total = $array[Data_length]+$array[Index_length]; if ( $array[Data_length] > 0 ) { print('<tr><td align="center">'); print(' ' . $array[Name] . '<br /></td><td align="center">'); if ( $array[Data_length] < 1024 ) { echo ' '.$array[Data_length].'</td><td align="center">'; } elseif ( ($array[Data_length] > 1024) && ($array[Data_length] < 1048576 ) ) { printf('%.0fK',($array[Data_length] / 1024) ); print('</td><td align="center">'); } elseif ( $array[Data_length] >= 1048576 ) { printf('%.2fMB',($array[Data_length] / 1048576) ); print('</td><td align="center">'); } if ( $array[Index_length] < 1024 ) { echo ' '.$array[Index_length].'<br /></td><td align="center">'; } elseif ( ($array[Index_length] > 1024) && ($array[Index_length] < 1048576 ) ) { printf('%.0fK',($array[Index_length] / 1024) ); print('<br /></td><td align="center">'); } elseif ( $array[Index_length] >= 1048576 ) { printf('%.2fMB',($array[Index_length] / 1048576) ); print('<br /></td><td align="center">'); } if ( $total < 1024 ) { echo ' '.$total.'<br /></td><td align="center">'; } elseif ( ($total > 1024) && ($total < 1048576 ) ) { printf('%.0fK',($total / 1024) ); print('<br /></td><td align="center">'); } elseif ( $total >= 1048576 ) { printf('%.2fMB',($total / 1048576) ); print('<br /></td><td align="center">'); } echo ' '.$array[Rows].'</td><td align="center"> '.$array[Avg_row_length].'</td></tr> '; } } ?> ~~~ * * * * * 参考资料: http://en.latindevelopers.com/ivancp/2012/a-better-show-table-status/ A Better SHOW TABLE STATUS