Page 1 of 1

Ifelse in before edit

Unread postPosted: Mon May 31, 2021 9:15 pm
by GlenMcCabe
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

Re: Ifelse in before edit

Unread postPosted: Mon May 31, 2021 9:19 pm
by kev1n
Comparisons are done using the == operator.

https://www.w3schools.com/php/php_operators.asp

wrong:
Code: Select all
$dt='locality'


correct:
Code: Select all
$dt=='locality'



PS: Please use Code tags to format the code.

Re: Ifelse in before edit

Unread postPosted: Mon May 31, 2021 9:23 pm
by GlenMcCabe
So simple. Thanks Kevin