Page 1 of 1

Inlude select dates in json array

Posted: Wed Apr 21, 2021 2:15 pm
by GlenMcCabe
I have the following code to create an array for graphing. It lives in the before edit of the form

$a[] = ['Reason', 'Referrals'];

$sd="#start_date#";
$ed="#end_date#";

$s = "
SELECT
referral_reasons.reasonforreferral AS reason,
COUNT(referral.referralreasonsID) AS Referrals
FROM
referral
LEFT JOIN referral_reasons ON referral.referralreasonsID=referral_reasons.id
WHERE
(referral.referralDate BETWEEN '$sd' AND '$ed')
GROUP BY referral.referralreasonsID
";

$t = nuRunQuery($s);

while($r = db_fetch_row($t)){
$a[] = [$r[0], Floatval($r[1])];
}
$j = "gdata = " . json_encode($a) . ";";

nuAddJavascript($j);

I need to display the dates ( $sd $ed) as part of the graph. Can I build them into the array? Are they available within an HTLM object on the form?

Now sorted - the dates are available within the js script of the HTML object.

Re: Inlude select dates in json array

Posted: Wed Apr 21, 2021 2:35 pm
by GlenMcCabe
Problem sorted. I can access the dates within the js script.