Keffe schreef:Wat mij uberhaupt al opvald is dat $i nooit 12 zal worden omdat jij zegt dat de waarde $i allen minder mag zijn dan 12 door dit: $i < 12. dit wil zeggen dat hij tot 11 mag gaan en dan stoppen. Maar in jou code zie ik een waarde 12. Dit stukje code klopt ook niet omdat je daar eigenlijk zegt dat $i altijd 12 wordt. Volgens mij mis jij een = dus zou het moeten zijn:
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/for"]for[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$i[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #0000BB]$i[/COLOR] [COLOR= #007700]<=[/COLOR] [COLOR= #0000BB]12[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #0000BB]$i[/COLOR][COLOR= #007700]++){[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$db[/COLOR][COLOR= #007700]->[/COLOR]query[COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT COUNT(*) AS count FROM transactions WHERE MONTH(date) = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700])->[/COLOR]fetch_assoc[COLOR= #007700]()){[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$i[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]12[/COLOR][COLOR= #007700]){[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"["[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]","[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]count[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]"]"[/COLOR][COLOR= #007700];
}[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"["[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]","[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]count[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]"],"[/COLOR][COLOR= #007700];
}
}
}[/COLOR]
?>
Misschien dat dit jou probleem al op zou lossen dat weet ik niet zeker omdat ik de code zelf niet kan testen.
Werkt helaas niet.

Stef schreef:Je kan beter dmv AJAX de gegevens uit een JSON bestand halen.
Ik genereer ook een grafiek en haal de data op met de volgende code:
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$.post("graphdata.php", {
accountID: accountID
},
function(data, status){
var results = JSON.parse(data);
var resultCount = 0;
results.forEach(function(entry) {
if(resultCount == 0) {
timestamps.push(entry[Timestamp].substr(12, 5) + " " + entry[Timestamp].substr(24, 2));
// timestamps.push(entry[Timestamp]);
followers.push(entry[DataA]);
}
resultCount++;
if(resultCount == 28) { //28 = 7 dagen
resultCount = 0;
}
});
timestamps.reverse();
followers.reverse();
drawGraph(timestamps, followers);
});
Ik gebruik Flot charts, die werkt met een
en achteraf heb je dan de data variabele in JS waarmee je de data invult. Gaat jouw manier dan nog steeds op? Ik zie bij jou namelijk eerst de data ophalen en dan drawGraph() uitvoeren, maar dat gebeurt hier dus andersom.
Milan schreef:12 keer een query uitvoeren lijkt me niet de meeste efficiënte manier.. Je kunt ook per maand groeperen en dan simpel fetchen. Daarnaast zou ik de data async ophalen via een AJAX call als JSON.
Zie ook deels hierboven wat betreft JSON. Over de efficiëntie: Een query met SELECT date FROM transactions GROUP BY MONTH(date)?