Ifelse in before edit

Questions related to using nuBuilder Forte.

Ifelse in before edit

Unread postby GlenMcCabe » Mon May 31, 2021 9:15 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
Attachments
page.png
page.png (72.54 KiB) Viewed 121 times
Last edited by GlenMcCabe on Mon May 31, 2021 9:19 pm, edited 1 time in total.
GlenMcCabe
 
Posts: 91
Joined: Sun Sep 29, 2019 8:10 pm

Re: Ifelse in before edit

Unread postby kev1n » Mon May 31, 2021 9:19 pm

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.
kev1n
nuBuilder Team
 
Posts: 1873
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Ifelse in before edit

Unread postby GlenMcCabe » Mon May 31, 2021 9:23 pm

So simple. Thanks Kevin
GlenMcCabe
 
Posts: 91
Joined: Sun Sep 29, 2019 8:10 pm


Return to General

Who is online

Users browsing this forum: No registered users and 20 guests

cron