0

我正在尝试将 mysql 查询表导出到 excel 文件。我让它在我网站上的另一个页面上工作,但它似乎在处理这个特定查询时遇到了问题。我收到此错误:

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 中运行良好。

4

1 回答 1

0

问题解决了!我是调用错误的数据库,菜鸟错误。

于 2012-07-31T20:56:50.290 回答