-1

i am trying to select 2 values from 2 different tables and getting this error. when i only selected from 1 table its worked. this is my code (after changing it already when looking on answers to this problem n line):

$apartmentNum = $_GET['apartmentNumber'];



$getBillsSumQuery = "SELECT a.totalBillsAmount , b.count(id) FROM apartments AS a , bills AS b WHERE a.number = "'.$apartmentNum.'" AND b.apartmentNumber = '.$apartmentNum.'";

$totalSum = mysqli_query($con,$getBillsSumQuery);

$row = mysqli_fetch_assoc($totalSum); //this is where the program crushes

$newSum = $row['totalBillsAmount'];

$billsCount = $row['count(id)'];


echo '{"billSum":' . $newSum . ' , "billCount":' . $billsCount .'}';
A.T
  • 71
  • 2
  • 9

1 Answers1

0

You need to write count(b.id) instead of b.count(id). Use below query.

$getBillsSumQuery = "SELECT a.totalBillsAmount , count(b.id) FROM apartments AS a , bills AS b 
WHERE a.number = "'.$apartmentNum.'" AND b.apartmentNumber = '.$apartmentNum.'";
RJParikh
  • 4,096
  • 1
  • 19
  • 36