//导出数据: //链接数据库 $link = mysqli_connect('127.0.0.1','root','root','everday'); //设置字符集 mysqli_query($link,"set names utf-8"); //sql语句 $sql = "select * from books"; //执行语句 $array = mysqli_query($link,$sql); //mysqli_fetch_assoc() 函数从结果集中取得一行作为关联数组。 循环追加到新数组 while ($re = mysqli_fetch_assoc($array)){ $arr[] = $re; }
数据为:
//拼接格式 $newArr = "ID\t名称\t原价\t现价\n"; foreach ($arr as $key=>$val){ $newArr.=$val['id']."\t".$val['name']."\t".$val['price']."\t".$val['x_price']."\n"; }
格式为: