I am trying to populate mysql data to a line chart using php.My data is in the following style in mysql database.
amt
---
700
250
180
190
720
For passing these values to line chart i need the data in the below format.
[700,250,180,190,720]
When i am trying with the below code, i am getting this below output.
["720"]
Here is my code.
<?php
$sql= "SELECT sum(wlt_txn_amount)as amt FROM wallet_txns where wlt_holder_id = '1' and wlt_txn_del_flg = 'N' and wlt_txn_cat <> 'Transfer' and wlt_txn_type = 'Expense' and wlt_txn_date between DATE (DATE_SUB(LAST_DAY(DATE_ADD(NOW(), INTERVAL 0 MONTH)),INTERVAL DAY(LAST_DAY(DATE_ADD(NOW(), INTERVAL 0 MONTH)))-1 DAY)) and date(CURDATE()) group by wlt_txn_cat ORDER BY wlt_txn_amount desc";
$result = mysqli_query($GLOBALS["___mysqli_ston"], $sql) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
if ( mysqli_num_rows($result) >0)
while($row = mysqli_fetch_array($result)){
$a = $row['amt'];
$c = array($a);
}
echo json_encode ($c);
?>
This is the first time i am trying to create a chart, if there is any big mistake in the code which i am using, sorry for that. Advance thanks for the advice and support.
$cin yourwhileloop, so$cend up with the last value. Check this out to see how to add items to$cinstead of reassigning it.