Satyam Gupta Satyam Gupta - 4 months ago 8
PHP Question

Join query error unknown index

Where i am wrong on this query result can someone help me.

<?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'];
}
?>

Answer

There's a typo in your query:

total_fund .name

should be written as:

total_fund.name

and you probably need an AS alias, anyway it's better to write your query this way:

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