php - Putting data from two different loops in a google pie chart -


so have code google pie chart (pie chart code not included, works fine , displays data)

<?php      $query = "select * category type = 'expense' ";     $select_category_list = mysqli_query($connection, $query);     while($row = mysqli_fetch_assoc($select_category_list)) {     $cat_id = $row['id'];     $cat_title = $row['title'];     echo "['$cat_title'" . ",";    echo "$cat_id],"; } ?> 

i put echo in different lines, not matter if in 1 line or in 2 lines, matters working :) instead of $cat_id want put sum ($cat_amount) calculated code:

$query = "select category_id, sum(amount) totalamount spendee type = 'expense' group category_id ";     $expense_query = mysqli_query($connection, $query);     while ($row = mysqli_fetch_assoc($expense_query)) {          $cat_amount = $row['totalamount'];     } 

i have tried putting while loop in while loop, foreach loop in while loop, putting $cat_amount instead of $cat_id (that displays 1 sum) , on. nothing worked. have not tried loop, assume result same + not sure how define times loop needs run, since there many type 'expense' categories added in time.

any appreciated. thank , have lovely day.

maybe i'm missing something, looks join 2 tables in 1 query

this desired result in 1 query / loop...

sql:

select a.title title, sum(b.amount) totalamount category a, spendee b b.category_id = a.id , b.type = 'expense' group a.title

php:

<?php   $query = "select a.title title, sum(b.amount) totalamount category a, spendee b b.category_id = a.id , b.type = 'expense' group a.title";   $select_category_list = mysqli_query($connection, $query);   while ($row = mysqli_fetch_assoc($select_category_list)) {     $cat_title = $row['title'];     $cat_amount = $row['totalamount'];     echo "['$cat_title'" . ",";     echo "$cat_amount],";   } ?> 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -