加入查询错误未知索引

时间:2016-07-23 20:50:31

标签: php mysql

如果我对此查询结果有误,可以有人帮助我。

<?php

include 'dbconfig.php';
$sql = 'SELECT SUM(total_fund.total_funds), total_fund .name from total_fund join project 
        WHERE total_fund.funds_id = project.project_id AND project_id=1200 GROUP BY project.project_id';
$retval = mysqli_query($dbconfig, $sql);

while ($data = mysqli_fetch_array($retval)) {

    echo $data['total_funds'] . '</br>';
    echo $data['name'];
}
?>

2 个答案:

答案 0 :(得分:1)

您的查询中有一个拼写错误:

total_fund .name

应写成:

total_fund.name

并且您可能需要一个AS别名,无论如何,以这种方式编写查询会更好:

select
  total_fund.name
  SUM(total_fund.total_funds) as total_funds
from
  total_fund join project on total_fund.funds_id = project.project_id
where
  project_id=1200
group by
  total_fund.name

答案 1 :(得分:0)

这是完整的查询

<?php

include 'dbconfig.php';
$sql = 'SELECT SUM(total_fund.total_funds)AS total, total_fund .name, project.Amount_to_be_raised from total_fund join project 
        where total_fund.funds_id = project.project_id AND project_id=1200';
$retval = mysqli_query($dbconfig, $sql);

while ($data = mysqli_fetch_array($retval)) {

    echo $data['total'] . '</br>';
    echo $data['name'];
}
?>