Home >Backend Development >PHP Tutorial > PHP怎么将查询结束导出Excel
PHP如何将查询结束导出Excel
<form action="user.php" method="POST"><br /> 用户编号:<input type="text" name="u_num" size="12" value="<?php echo $_POST['u_num']; ?>" /> <br /> 用户名:<input type="text" name="u_name" size="20" value="<?php echo $_POST['u_name']; ?>" /> <br /> <input type="submit" name="sub" value=" 查询 " /> <br /> <input type="button" value="导出Excel" /><br /> </form><br /> <br /> <table><br /> <tr><br /> <td>用户编号</td><br /> <td>用户名</td><br /> </tr><br /> <br /> <?php <br /> if(!empty($_POST["u_num"])){<br /> $u_num = "where u_id='"."{$_POST['u_num']}"."'";<br /> }<br /> <br /> $sql = "select * from msd.dbo.user";<br /> <br /> $query = sqlsrv_query($conn,$sql);<br /> if( $query === false) {<br /> die( print_r( sqlsrv_errors(), true) );<br /> }<br /> <br /> while($row = sqlsrv_fetch_array($query)) {<br /> echo "<tr><td>$row[0]</td><td>$row[1]</td></tr>";<br /> }<br /> <br /> sqlsrv_free_stmt( $query);<br /> sqlsrv_close( $conn);<br /> ?><br /> <br /> </table>