Getting data from database into a php array
i've been having an error for about 2 days now i'd appreaciate if someone
could help me.
I want to make a query that selects all payments in a month and save them
in an array, i wanna graph this so i also need the days where no payments
were done. this is my code and i think my problem is when i try to catch
them in an array. When i call my function from my main page all my website
goes down.
function getDailyGraph($membership, $selectedMonth){
$sql = "SELECT rate_amount AS payment, DAY(date) AS day FROM
payments WHERE membership_id = ".$membership.
" AND MONTH(date) = ".$selectedMonth." ORDER BY day";
$query = $db->query($sql);
$days = array();
for ($i=1; $i <= 31 ; $i++) {
$payment = mysql_fetch_array($query);
# code...
if ($i == $payment['dia']) {
# code...
$days[] = $payment['payment'];
}else{
$days[] = 0;
}
}
return $days;
}
No comments:
Post a Comment