If value of POST = "0" then $Vid = "$row['video'] - if-statement

if ($_POST['video'] == '0 lets say') {the $vid=$row['video']}
how would i define this correctly
so that i can set the value of video in the initial post form
as 0 lets say or any other number,
and on recieving the value through If isset$post
- if the value actually equals "0 lets say"
then $vid can = $row['video']
Basically
how can this be achieved,... thank you

if ($_POST['video'] == '0') {
$videoID = $vid;
} else {
$videoID = $videoID;
}
sorry i should of looked around 1st. but thanks for any interest...

Related

Why does thinkscript throw these issues when I try to create a counter?

When I try to create a counter and increment it in an if-else statement the thinkscript compiler throws confusing errors which tell me it's not allowed, yet I've seen this done in several examples. They even have a reserved word: rec in order to allow for incrementing counters.
score = score + 1; produces: # Already assigned: Score at...
rec score = score + 1; produces: # identifier already used: score at ...
# not allowed inside an IF/THEN/ELSE statement
#
# TD Ameritrade IP Company, Inc. (c) 2017-2019
#
input price = close;
input length = 9;
input displace = 0;
def score = 0;
def smavrgg = Average(price[-displace], length);
def expMvAvrg = ExpAverage(price[-displace], length);
plot SMA = smavrgg;
SMA.SetDefaultColor(GetColor(1));
plot AvgExp = expMvAvrg;
AvgExp.SetDefaultColor(GetColor(1));
# 1 if uptrend, 0 if downtrend
def lastTrendisUp = (close[0] - close[1]) > 0 ;
def secondLastTrendisUP = (close[1] - close[2]) > 0;
def thirdLastTrendisUP = (close[2] - close[3]) > 0;
def fourthLastTrendisUP = (close[3] - close[4]) > 0;
input lookback = 5;
# defines intBool (array) that indicates whether one or the other crossed.
def bull_cross = SMA crosses above AvgExp;
def bear_cross = AvgExp crosses below SMA;
# returns the highest value in the data array for the lookback.
# so [0, 1, 0, 0] means a cross happened within the last units. and 1 will be returned.
if (bull_cross[0] or bear_cross[0]) then {
if lastTrendisUp {
# Already assigned: Score at...
score = score + 1;
# identifier already used: score at ...
# not allowed inside an IF/THEN/ELSE statement
rec score = score + 1;
} else {
}
} else if (bull_cross[1] or bear_cross[1]) {
if secondLastTrendisUP {
} else {
}
} else if (bull_cross[2] or bear_cross[2]) {
if thirdLastTrendisUP {
} else {
}
} else if (bull_cross[3] or bear_cross[3]) {
if fourthLastTrendisUP {
} else {
}
} else if (bull_cross[4] or bear_cross[4]) {
} else {
}
# If most recent cross happened in the last 4
# and most recent cross occured on a green candle.
def bull_lookback = Highest(bull_cross, lookback);
def bear_lookback = Highest(bear_cross, lookback);
# def think = if bull_lookback or bear_lookback
plot signal = if bull_lookback then 2 else if bear_lookback then 1 else 0;
signal.AssignValueColor(if signal == 2 then Color.DARK_GREEN else if signal == 1 then Color.DARK_RED else Color.DARK_ORANGE);
AssignBackgroundColor(if signal == 2 then Color.DARK_GREEN else if signal == 1 then Color.DARK_RED else Color.DARK_ORANGE);
Once you define a variable in Thinkscript and assign it, it's only valid for one bar, it behaves as a constant so it can't be reassigned. I'm pretty sure you can't even place a Def command into a conditional, just like in most codes. In order to create a 'dynamic' SCORE, you need to assign the dynamic value in the same line you instantiate. You don't need
def score = 0;
since when you define the variable, it will have a zero value anyway.
You also don't the extra variables for the 'trendisup' placeholders, because really
secondLastTrendisUp
is the same as saying
lastTrendisUp[1]
because it was already computed in the last bar.
You can accomplish the counter without the extra variables using a FOLD statement, like this:
def score= fold index=0 to 4
with p=0
do p + ((bearcross[index] or bullcross[index]) and lastTrendisUp[index]);
This will add one to the score each time the conditions are true, and assign the total to the SCORE variable. I think this is what you would like to accomplish, I can't tell, since you never show what you're doing with the score variable later on... If you are looking to just find out if bullcross or bearcross condition and also the lasttrendisup condition evaluates to true in any of the last five bars, then you add 'while p=0' above the with, and it will return a one to SCORE as soon as it encounters the first true instance.
counter to increase a variable by 1, on each bar:
score = score[1] + 1;
the [1] means, go get the value from that variable from 1 bar ago.
The answer is that variables in thinkscript cannot be changed.

Very simple if/else statements seem to be working backwards

I have been looking at this simple if/else statement in another larger project and I can't seem to find what I am doing wrong.
I have inserted Logger.log() in both if statements to try to root out the problem.
When I run the code, I get the following Log:
[19-02-24 08:50:05:427 PST] var Campus = Baylor
[19-02-24 08:50:05:428 PST] var TSTCCampus = TSTC
[19-02-24 08:50:05:428 PST] if IS= statement executed
[19-02-24 08:50:05:428 PST] else NOT= executed
The two variables are clearly NOT equal but the if = executes and the else != executes.
What am I doing wrong?
function myFunction() {
// call the Current Reults sheet and identify the Last Row of Responses
var RawFormResponsesSheet = SpreadsheetApp.getActive().getSheetByName("Current Results");
var CurrentSubmission = RawFormResponsesSheet.getLastRow(); // Retruns the Value of the Last Submission Row Number
var Campus = RawFormResponsesSheet.getRange(CurrentSubmission,3).getValue();
// call the Email Data sheet and identify certain cell values
var EmailDataSheet = SpreadsheetApp.getActive().getSheetByName("Email Data")
var TSTCCampus = EmailDataSheet.getRange(3, 4).getValue();
var BaylorCampus = EmailDataSheet.getRange(4, 4).getValue();
Logger.log("var Campus = " + Campus)
Logger.log("var TSTCCampus = " + TSTCCampus)
if (Campus = TSTCCampus){Logger.log ("if IS= statement executed")}
else {Logger.log ("else IS= executed")}
if (Campus != TSTCCampus){Logger.log ("if NOT= statement executed")}
else {Logger.log ("else NOT= executed")}
}
You need to use == as comparison operator.
There are 3 = operators/commands:
= is used to set the value of a variable
== equality operator, returns true if the elements have same value, performs type conversion
=== identity operator, similar to ==, but no type conversion
The following explains what type conversion is.
"5" == "5" returns true
"5" == 5 returns true
"5" === "5" returns true
"5" === 5 returns false
somevar = 5 assigns and returns 5, which is a truthy value, and thus if (x = 5) { will always execute the conditional body. Similarly if (x = 0) { will never execute the conditional body, because it assigns and returns 0, which is falsy.

Crystal Report converting value to number with symbol

I have an issue with a Crystal Report that I'm creating. I am using fields from a database and am pulling in the result value where the analysis field is equal to certain values.
In the condition the first check looks at the analysis field and checks if its equal to "Conf". The result for this is "<10"
The second check looks at the analysis field and checks if its equal to "Original". The result for this is "20".
I want the results to display in the order above however with the following basic logic it returns the result of 20.
if analysis = "conf" then result
else if analysis = "Original" then result
I was having this issue with multiple records however solved it by converting both results to numbers (toNumber(Result)). However this record has the less than symbol contained within the field value which causes the conf result to "be skipped" and will display the original result instead. I've tried a few things without success. Here is the code for the condition of where I'm at below. I fell this is way to complex logic but I've just added to it as I've had ideas and it shows what I've tried.
if {UNITS} = "CFU_G" then
if {ANALYSIS} = "CONF" and
{RESULT}="" or
{RESULT} = "0" then 0
else if {ANALYSIS} = "CONF"
then if isNumeric({RESULT}) then
tonumber({RESULT}) else
tonumber(Replace ({RESULT}, "<", ""))
else
if {UNITS} = "CFU_G" then
if {ANALYSIS} = "Original" and
{RESULT}="" or
{RESULT} = "0" then 0
else if {ANALYSIS} = "Original"
then if isNumeric({RESULT}) then
tonumber({RESULT}) else
tonumber(Replace ({RESULT}, "<", ""))
Thanks,
Tom
This was the solution I came up with.
Field 1
whileprintingrecords;
stringvar vResult := "";
Field 2
whileprintingrecords;
stringvar vResult;
vResult := if {RESULT.UNITS} = "CFU_G"
and {RESULT.ANALYSIS} = "CRA_LIS_ENU_CONF_MPCRAM29"
then {RESULT.FORMATTED_ENTRY}
else if {RESULT.ANALYSIS} = "CRA_LIST_ENU_MPCRAM29"
and {RESULT.UNITS} = "CFU_G"
and vResult = ""
then {RESULT.FORMATTED_ENTRY}
Field 3
whileprintingrecords;
stringvar vResult;
vResult;

Loop problems Even Count

I have a beginner question. Loops are extremely hard for me to understand, so it's come to me asking for help.
I am trying to create a function to count the amount of even numbers in a user input list, with a negative at the end to show the end of the list. I know I need to use a while loop, but I am having trouble figuring out how to walk through the indexes of the input list. This is what I have so far, can anyone give me a hand?
def find_even_count(numlist):
count = 0
numlist.split()
while numlist > 0:
if numlist % 2 == 0:
count += 1
return count
numlist = raw_input("Please enter a list of numbers, with a negative at the end: ")
print find_even_count(numlist)
I used the split to separate out the indexes of the list, but I know I am doing something wrong. Can anyone point out what I am doing wrong, or point me to a good step by step explanation of what to do here?
Thank you guys so much, I know you probably have something more on your skill level to do, but appreciate the help!
You were pretty close, just a couple of corrections:
def find_even_count(numlist):
count = 0
lst = numlist.split()
for num in lst:
if int(num) % 2 == 0:
count += 1
return count
numlist = raw_input("Please enter a list of numbers, with a negative at the end: ")
print find_even_count(numlist)
I have used a for loop rather than a while loop, stored the outcome of numlist.split() to a variable (lst) and then just iterated over this.
You have a couple of problems:
You split numlist, but don't assign the resulting list to anything.
You then try to operate on numlist, which is still the string of all numbers.
You never try to convert anything to a number.
Instead, try:
def find_even_count(numlist):
count = 0
for numstr in numlist.split(): # iterate over the list
num = int(numstr) # convert each item to an integer
if num < 0:
break # stop when we hit a negative
elif num % 2 == 0:
count += 1 # increment count for even numbers
return count # return the total
Or, doing the whole thing in one line:
def find_even_count(numlist):
return sum(num % 2 for num in map(int, numlist.split()) if num > 0)
(Note: the one-liner will fail in cases where the user tries to trick you by putting more numbers after the "final" negative number, e.g. with numlist = "1 2 -1 3 4")
If you must use a while loop (which isn't really the best tool for the job), it would look like:
def find_even_count(numlist):
index = count = 0
numlist = list(map(int, numlist.split()))
while numlist[index] > 0:
if numlist[index] % 2 == 0:
count += 1
index += 1
return count

Log base 2 calculation in python

I am trying to calculate the average disorder in ID trees. My code is below:
Republican_yes = yes.count('Republican')
Democrat_yes = yes.count('Democrat')
Republican_no = no.count('Republican')
Democrat_no = no.count('Democrat')
Indep_yes = yes.count('Independent')
Indep_no = no.count('Independent')
disorder_yes= Republican_yes/len(yes)*(math.log(float(Republican_yes)/len(yes),2))+ Democrat_yes/len(yes)*(math.log(float(Democrat_yes)/len(yes),2))+Indep_yes/len(yes)*(math.log(float(Indep_yes)/len(yes),2))
disorder_no= Republican_no/len(no)*(math.log(float(Republican_no)/len(no),2))+Democrat_no/len(no)*(math.log(float(Democrat_no)/len(no),2))+Indep_no/len(no)*(math.log(float(Indep_no)/len(no),2))
avgdisorder = -len(yes)/(len(yes)+len(no))*disorder_yes - len(no)/(len(yes)+len(no))*disorder_no
return avgdisorder
why do I keep getting math domain error?
Check if the lengths are 0 or not, else you will get MathError.
if len(yes):
disorder_yes= Republican_yes/len(yes)*(math.log(float(Republican_yes)/len(yes),2))+ Democrat_yes/len(yes)*(math.log(float(Democrat_yes)/len(yes),2))+Indep_yes/len(yes)*(math.log(float(Indep_yes)/len(yes),2))
if len(no):
disorder_no= Republican_no/len(no)*(math.log(float(Republican_no)/len(no),2))+Democrat_no/len(no)*(math.log(float(Democrat_no)/len(no),2))+Indep_no/len(no)*(math.log(float(Indep_no)/len(no),2))
if len(yes) or len(no):
avgdisorder = -len(yes)/(len(yes)+len(no))*disorder_yes - len(no)/(len(yes)+len(no))*disorder_no
If you want, you can always add the else clause for all 3 if statements as per your requirement.