Ifelse in before edit
Posted: Mon May 31, 2021 1:45 pm
I have the following code in a form to display charts
$sd="#start_date#";
$ed="#end_date#";
$dt="#data_type#";
if($dt='locality') {
$a[] = ['Location', 'Referrals'];
$s = "
SELECT
referral.locality AS location,
COUNT(referral.locality) AS Referrals
FROM
referral
WHERE
(referral.referralDate BETWEEN '$sd' AND '$ed')
GROUP BY referral.locality
";
}elseif($dt='owner') {
$a[] = ['Owner', 'Referrals'];
$s = "
SELECT
practitioners.name AS owner,
COUNT(referral.ownerID) AS Referrals
FROM
referral
LEFT JOIN practitioners ON referral.ownerID=practitioners.id
WHERE
(referral.referralDate BETWEEN '$sd' AND '$ed')
GROUP BY practitioners.name
";
}else {
$a[] = ['Reason', 'Referrals'];
$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 have used nudebug to show that my drop downs are working properly.
I always produce gdata array from the first element of the if else construct no matter which data type I choose. If I rearrange the select statements the contents of gdata change but are always the first element. I have tried the if statements with and without ' around the value. i.e. if($dt=location) and if($dt='location')
F12 does nor show any errors.
Glen
$sd="#start_date#";
$ed="#end_date#";
$dt="#data_type#";
if($dt='locality') {
$a[] = ['Location', 'Referrals'];
$s = "
SELECT
referral.locality AS location,
COUNT(referral.locality) AS Referrals
FROM
referral
WHERE
(referral.referralDate BETWEEN '$sd' AND '$ed')
GROUP BY referral.locality
";
}elseif($dt='owner') {
$a[] = ['Owner', 'Referrals'];
$s = "
SELECT
practitioners.name AS owner,
COUNT(referral.ownerID) AS Referrals
FROM
referral
LEFT JOIN practitioners ON referral.ownerID=practitioners.id
WHERE
(referral.referralDate BETWEEN '$sd' AND '$ed')
GROUP BY practitioners.name
";
}else {
$a[] = ['Reason', 'Referrals'];
$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 have used nudebug to show that my drop downs are working properly.
I always produce gdata array from the first element of the if else construct no matter which data type I choose. If I rearrange the select statements the contents of gdata change but are always the first element. I have tried the if statements with and without ' around the value. i.e. if($dt=location) and if($dt='location')
F12 does nor show any errors.
Glen