再次请教各位高手,熟手,老手,关于查询多个表及生成excel文件的问题!

victorhero 2005-10-13 01:14:17
现想生成excel文件,但是数据不在一个表中,分散在三个表中,三个表的结构完全一致,现想用一条语句查询三个表的数据,然后生成excel文件,请问该如何做?能给出生成excel的代码吗?我现在只能查询一个表,而且只能下载一个字段的内容。

关于多表查询,我想用select * from table1 where flag = 1 union all select * from table2 where flag = 1 union all select * from table3 where flag =1,但是php中不能用。
后来我用select xx,xx,xx from table1,table2,table3 where flage =1 还是不能用。

请问该如何做?
...全文
198 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
mrshelly 2005-10-19
  • 打赏
  • 举报
回复
升级到MYSQL 4.0以上。
victorhero 2005-10-19
  • 打赏
  • 举报
回复
「已注销」 2005-10-19
  • 打赏
  • 举报
回复
union 4.0.0开始支持。
存储过程在4.1开始支持。

针对楼主的需求,4.0以上就行了,
另外,sql语句有问题,注意语法格式,就像数学运算中的括号一样,别忘了:)呵呵
gu1dai 2005-10-19
  • 打赏
  • 举报
回复
升级到mysql4.1以上。
victorhero 2005-10-15
  • 打赏
  • 举报
回复
各位,如何实现联合查询啊!!如上
gh502 2005-10-14
  • 打赏
  • 举报
回复
写在存储过程里
victorhero 2005-10-13
  • 打赏
  • 举报
回复
不行,好像不能使用union......
coolstr 2005-10-13
  • 打赏
  • 举报
回复
php生成excel文档[虽然没什么功能,但是免费可以交货]

<?
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
?>
coolstr 2005-10-13
  • 打赏
  • 举报
回复
SQL语句改成这样试试;
select * from table1 where table1.flag = 1 union all select * from table2 where table2.flag = 1 union all select * from table3 where table3.flag =1

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧