Foreach嵌套For
<?php $db=new MySQLi("localhost","账号","密码","数据库名"); //链接数据库 $sql=$db->query("select * from 表名"); //执行SQL语句查询 $arrt=$sql->fetch_all(); echo"<table border='1' width='100%'>"; foreach($arrt as $v) //遍历数组 { echo "<tr>"; for($a=开始列数;$a<=结束列数;$a++) { echo"<td>$v[$a]</td> "; } echo"</tr>"; } echo "</table>"; ?>