0
我想将一个mysql查询表导出到excel文件。我有它在我的网站上的另一个页面上工作,但它似乎遇到此特定查询的麻烦。 我得到这个错误:PHPExcel列未找到:1054
Warning: PDO::query() [pdo.query]: SQLSTATE[42S22]: Column not found: 1054
Unknown column 'u2.confirmed_cash' in 'field list' in
/home2/jtdsdevc/public_html /rbk/usage-v3/inc/excel-exporter
/MySqlExcelBuilder.class.php on line 130
这是我的代码。
// Setup the SQL Statements
$sql_statement = getReport($idLeague, $idTeam);
function getReport($idLeague, $idTeam){
global $connect;
$sql = "
SELECT idPlayer AS id,
(SELECT CONCAT_WS(' ', location, name) FROM `team` WHERE `team`.id = u.idTeam) AS team,
(SELECT CONCAT_WS(' ', first_name, last_name) FROM `player` WHERE `player`.id = u.idPlayer) AS name,
(SELECT u2.confirmed_cash FROM `usage` u2 WHERE u.idPlayer = u2.idPlayer ORDER BY date DESC LIMIT 1) AS total_cash,
(SELECT u2.confirmed_product FROM `usage` u2 WHERE u.idPlayer = u2.idPlayer ORDER BY date DESC LIMIT 1) AS total_product,
max(date) AS last_entry
FROM `usage` u INNER JOIN `team` t ON u.idTeam =t.id INNER JOIN `league` l ON t.idLeague =l.id WHERE (t.idleague =".$idLeague." or l.pID =".$idLeague.")
";
return $sql;
}
// Add the SQL statements to the spread sheet
$mysql_xls->add_page('Report',$sql_statement);
// Get the spreadsheet after the SQL statements are built...
$phpExcel = $mysql_xls->getExcel(); // This needs to come after all the pages have been added.
....
这就是错误发生的地方。在MySqlExcelBuilder.class.php文件的确切行是:
if ($sh = $this->pdo->query($sql))
的$sql
变量上面出来是
SELECT idPlayer AS id,
(SELECT CONCAT_WS(' ', location, name) FROM `team` WHERE `team`.id = u.idTeam) AS team,
(SELECT CONCAT_WS(' ', first_name, last_name) FROM `player` WHERE `player`.id = u.idPlayer) AS name,
(SELECT u2.confirmed_cash FROM `usage` u2 WHERE u.idPlayer = u2.idPlayer ORDER BY date DESC LIMIT 1) AS total_cash,
(SELECT u3.confirmed_product FROM `usage` u3 WHERE u.idPlayer = u3.idPlayer ORDER BY date DESC LIMIT 1) AS total_product,
max(date) AS last_entry
FROM `usage` u
INNER JOIN `team` t ON u.idTeam =t.id
INNER JOIN `league` l ON t.idLeague =l.id
WHERE (t.idleague =1 or l.pID =1)
编辑:还值得一提的是,通过自身的查询中工作正常phpMyAdmin的。
那么列'usage.confirmed_cash'是否存在?不确定它是否在'SELECT'列表中很重要,但是您使用别名'u2'作为两个不同的查询。将第二个更改为不同的别名。 – 2012-07-18 17:20:59
我按照你的建议做了,仍然没有骰子。该列确实存在于表中,事实上,当我将复制/粘贴该查询(并将变量替换为phpMyAdmin)时,它工作得很好! – Falantar014 2012-07-18 18:08:07
只是为了澄清任何人读这个,MySqlExcelBuilder.class.php不是PHPExcel的一部分(否则我会被问起它在PHPExcel库中的人问questiosn) – 2012-07-18 19:24:18