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
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Ifelse in before edit
-
- Posts: 114
- Joined: Sun Sep 29, 2019 12:40 pm
Ifelse in before edit
You do not have the required permissions to view the files attached to this post.
Last edited by GlenMcCabe on Mon May 31, 2021 1:49 pm, edited 1 time in total.
-
- nuBuilder Team
- Posts: 4303
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 445 times
- Contact:
Re: Ifelse in before edit
Comparisons are done using the == operator.
https://www.w3schools.com/php/php_operators.asp
wrong:
correct:
PS: Please use Code tags to format the code.
https://www.w3schools.com/php/php_operators.asp
wrong:
Code: Select all
$dt='locality'
Code: Select all
$dt=='locality'
PS: Please use Code tags to format the code.
-
- Posts: 114
- Joined: Sun Sep 29, 2019 12:40 pm