In general websites, we will usually see that the data of many database tables are displayed in the browser They all appear in the table, which makes me feel amazing at first, but if you think about it carefully, it is not too complicated. Since you can return dql and dml in general, it should not be a problem to return it in the form of a table. However, there is one point to explain. What is wrong is that it is wrong to design a script on the client to implement the problem. Even if it can be implemented, it is very complicated. Therefore, we can only consider it on the server side. Think about the way to solve the problem, that is, print when returning Table labels and corresponding attributes and attribute values. Although this method seems unreasonable, it is also the most effective method. The specific code is as follows:
<?php //在表格中显示表的数据,常用方式 function ShowTable($table_name){ $conn=mysql_connect("localhost","root","toor"); if(!$conn){ echo "连接失败"; } mysql_select_db("test",$conn); mysql_query("set names utf8"); $sql="select * from $table_name"; $res=mysql_query($sql,$conn); $rows=mysql_affected_rows($conn);//获取行数 $colums=mysql_num_fields($res);//获取列数 echo "test数据库的"."$table_name"."表的所有用户数据如下:<br/>"; echo "共计".$rows."行 ".$colums."列<br/>"; echo "<table style='border-color: #efefef;' border='1px' cellpadding='5px' cellspacing='0px'><tr>"; for($i=0; $i < $colums; $i++){ $field_name=mysql_field_name($res,$i); echo "<th>$field_name</th>"; } echo "</tr>"; while($row=mysql_fetch_row($res)){ echo "<tr>"; for($i=0; $i<$colums; $i++){ echo "<td>$row[$i]</td>"; } echo "</tr>"; } echo "</table>"; } ShowTable("test1"); ?>