我对if语句有一个小问题,因为它只填充最后一个elseif
%%[IF @Add3 == "Y" AND @Add4 == "Y" AND @Add5 == "N" THEN
SET @WhichNom1 = "1"
SET @WhichNom2 = "2"
ELSEIF @Add3 == "Y" AND @Add4 == "N" AND @Add5 == "Y" THEN
SET @WhichNom1 = "1"
SET @WhichNom2 = "3"
ELSEIF @Add3 == "N" AND @Add4 == "Y" AND @Add5 == "Y" THEN
SET @WhichNom1 = "1"
SET @WhichNom2 = "3"
]%%
@WhichNom1
@WhichNom2
%%[ENDIF]%%
当最后一个ELSEIF为TRUE时,上面的代码将显示两个变量。我需要做些什么来检查3个语句并为每个场景显示哪一个和哪一个? 只有当最后一个elseif为真时才打印变量
像这样移动它们:
...
ELSEIF @Add3 == "N" AND @Add4 == "Y" AND @Add5 == "Y" THEN
SET @WhichNom1 = "1"
SET @WhichNom2 = "3"
]%%
%%[ENDIF]%%
@WhichNom1
@WhichNom2
所以它们在IF/ELSEIF之外。这样,它们将始终被打印出来,但是变量的设置将根据子句的不同而不同。
编辑:如果您只希望在其中一条语句为真时打印变量,那么您将(如您所提到的)需要在If语句中打印它们,或者您可以:
SET @WhichNom1 = ""
SET @WhichNom2 = ""
在if语句之前,然后在它们之后:
IF @WhichNom1 != "" THEN @WhichNom1
IF @WhichNom2 != "" THEN @WhichNom2
所以你只有在它们被设置为"以外的东西时才会打印它们
我使用两个IF语句以稍微不同的方式对它进行排序
%%[IF @Add3 == "Y" AND @Add4 == "Y" AND @Add5 == "N" THEN
SET @WhichNom1 = "1"
SET @WhichNom2 = "2"
SET @Status = "T"
ELSEIF @Add3 == "Y" AND @Add4 == "N" AND @Add5 == "Y" THEN
SET @WhichNom1 = "1"
SET @WhichNom2 = "3"
SET @Status = "T"
ELSEIF @Add3 == "N" AND @Add4 == "Y" AND @Add5 == "Y" THEN
SET @WhichNom1 = "2"
SET @WhichNom2 = "3"
SET @Status = "T"
ELSE
SET @Status = "F"
ENDIF]%%
%%[IF @Status == "T" THEN]%%
@WhichNom1
@WhichNom2
%%[ENDIF]%%
Rob是正确的。此外,如果您想在AMPscript
块之外打印@WhichNom1
和@WhichNom2
,您可能需要编写如下代码:
%%[
IF @Add3 == "Y" AND @Add4 == "Y" AND @Add5 == "N" THEN
SET @WhichNom1 = "1"
SET @WhichNom2 = "2"
SET @Status = "T"
ELSEIF @Add3 == "Y" AND @Add4 == "N" AND @Add5 == "Y" THEN
SET @WhichNom1 = "1"
SET @WhichNom2 = "3"
SET @Status = "T"
ELSEIF @Add3 == "N" AND @Add4 == "Y" AND @Add5 == "Y" THEN
SET @WhichNom1 = "2"
SET @WhichNom2 = "3"
SET @Status = "T"
ELSE
SET @Status = "F"
ENDIF
]%%
%%[ IF @Status == "T" THEN ]%%
%%= v(@WhichNom1) =%%<br />
%%= v(@WhichNom2) =%%
%%[ ENDIF ]%%