1

Hi I have some ampscript that pulls data in from the data extension into the email template. When I preview it the first section shows up 3 times as a duplicate but the other two sections show fine. I'm trying to stop the first section from showing up 3 times. I checked for similar questions but not having much luck. Maybe I need a second pair of eyes to see what I missed.

%%[

set @rows = LookupOrderedRows("Consult_Notifications_Daily_Digest",3,"date desc","EmailAddress",emailaddr)

]%%

%%[

set @rowCount = rowcount(@rows)

if @rowcount > 1 then

  for @i = 1 to @rowCount do

    set @row = row(@rows,@i)
    set @mentionNotificationType = field(@row,"NotificationType_Mention_1")
    set @mentionNotificationType = field(@row,"NotificationType_Mention_2")
    set @mentionNotificationType = field(@row,"NotificationType_Mention_3")

    set @mentionPostName = field(@row,"PostName_4")
    set @mentionPostName5 = field(@row,"PostName_5")
    set @mentionPostName6 = field(@row,"PostName_6")

    set @mentionTargetURL = field(@row,"targeturl_4")
    set @mentionTargetURL5 = field(@row,"targeturl_5")
    set @mentionTargetURL6 = field(@row,"targeturl_6")

    set @mentionRecipientName = field(@row,"RecipientName")
    set @mentionMentionedUser = field(@row,"MENTIONEDUSER")
    set @mentionActorName = field(@row,"ActorNameDeg")
    set @mentionUser = field(@row,"User_1")
    set @mentionPostTitle = field(@row,"PostTitle_4")
    set @mentionUserAccountUrl = field(@row,"UserAccountUrl")

    set @mentionActorAccountUrl = field(@row,"ActorAccountUrl_4")
    set @mentionActorAccountUrl5 = field(@row,"ActorAccountUrl_5")
    set @mentionActorAccountUrl6 = field(@row,"ActorAccountUrl_6")

    set @mentionThreadUrl = field(@row,"ThreadUrl_4")
    set @mentionThreadUrl5 = field(@row,"ThreadUrl_5")
    set @mentionThreadUrl6 = field(@row,"ThreadUrl_6")

    set @mentionDate = field(@row,"Date")

    set @mentionPostBody = field(@row,"PostBody_4")
    set @mentionPostBody5 = field(@row,"PostBody_5")
    set @mentionPostBody6 = field(@row,"PostBody_6")

      if @mentionNotificationType == 'User' then

]%%
-->

        <tr>
          <td style="padding: 7px 0 0 0;">
            <table width="560" cellpadding="0" cellspacing="0" borde="0" class="container">
              <tr>
                <td align="center" valign="middle" style="padding:2px 2px 3px 1px; box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.09);" bgcolor="#dfdfdf">
                  <table width="558" class="container" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
                    <tr>
                      <td style="padding:20px 20px 20px 20px; font-size: 14px;" align="left">
                        <table width="508" class="container" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
                          <tr>
                            <td width="508" style="padding: 0 0px 0 0;" class="container" colspan="1" valign="top">
                              <table width="508" class="container" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td align="left" style="font-size: 18px;font-family: 'Roboto Condensed','Helvetica',Arial,sans-serif; font-weight: none; padding:0 0 10px 0; line-height: normal;">
                                    <a href="%%=redirectTo(@mentionTargetURL)=%%" style="font-size: 18px;color: #000000;text-decoration:none;font-family: 'Roboto Condensed','Helvetica',Arial,sans-serif; font-weight: none; padding:0 0 10px 0; line-height: normal;">%%=v(@mentionPostName)=%%</a>
                                  </td>
                                </tr>
                                %%[if not empty(@mentionPostBody) then]%%
                                <tr>
                                  <td align="left" style="font-size: 14px;font-family: 'Roboto Condensed','Helvetica',Arial,sans-serif; font-weight: none; padding:0 0 10px 0; line-height: normal; color: #606060;">
                                    %%=v(@mentionPostBody)=%% .. <a href="%%=redirectTo(@followedReplyTargetURL)=%%" target="_blank" style="font-size: 14px;font-family: 'Proxima Nova','Helvetica',Arial,sans-serif; font-weight: normal; text-decoration: none; color: #007cb0;">read more</a>
                                  </td>
                                </tr>
                                %%[endif]%%
                                <tr>
                                  <td align="left" style="padding: 0px 0 0px 0; font-size: 14px;font-family: 'Proxima Nova','Helvetica',Arial,sans-serif; color: #3a3b3c;">
                                    <a href="%%=redirectTo(@mentionActorAccountUrl)=%%" target="_blank" style="font-size: 14px;font-family: 'Proxima Nova','Helvetica',Arial,sans-serif; font-weight: normal; text-decoration: none; color: #007cb0;">%%=v(@mentionRecipientName)=%%</a> responded to your post on %%=v(@mentionDate)=%%.
                                  </td>
                                </tr>
                              </table>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
 <!-- End script
%%[

else

endif next @i endif

]%%
-->


        <tr>
          <td style="padding: 7px 0 0 0;">
            <table width="560" cellpadding="0" cellspacing="0" borde="0" class="container">
              <tr>
                <td align="center" valign="middle" style="padding:2px 2px 3px 1px; box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.09);" bgcolor="#dfdfdf">
                  <table width="558" class="container" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
                    <tr>
                      <td style="padding:20px 20px 20px 20px; font-size: 14px;" align="left">
                        <table width="508" class="container" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
                          <tr>
                            <td width="508" style="padding: 0 0px 0 0;" class="container" colspan="1" valign="top">
                              <table width="508" class="container" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td align="left" style="font-size: 18px;font-family: 'Roboto Condensed','Helvetica',Arial,sans-serif; font-weight: none; padding:0 0 10px 0; line-height: normal;">
                                    <a href="%%=redirectTo(@mentionTargetURL5)=%%" style="font-size: 18px;color: #000000;text-decoration:none;font-family: 'Roboto Condensed','Helvetica',Arial,sans-serif; font-weight: none; padding:0 0 10px 0; line-height: normal;">%%=v(@mentionPostName5)=%%</a>
                                  </td>
                                </tr>
                                %%[if not empty(@mentionPostBody5) then]%%
                                <tr>
                                  <td align="left" style="font-size: 14px;font-family: 'Roboto Condensed','Helvetica',Arial,sans-serif; font-weight: none; padding:0 0 10px 0; line-height: normal; color: #606060;">
                                    %%=v(@mentionPostBody5)=%% .. <a href="%%=redirectTo(@followedReplyTargetUR5L)=%%" target="_blank" style="font-size: 14px;font-family: 'Proxima Nova','Helvetica',Arial,sans-serif; font-weight: normal; text-decoration: none; color: #007cb0;">read more</a>
                                  </td>
                                </tr>
                                %%[endif]%%
                                <tr>
                                  <td align="left" style="padding: 0px 0 0px 0; font-size: 14px;font-family: 'Proxima Nova','Helvetica',Arial,sans-serif; color: #3a3b3c;">
                                    <a href="%%=redirectTo(@mentionActorAccountUrl5)=%%" target="_blank" style="font-size: 14px;font-family: 'Proxima Nova','Helvetica',Arial,sans-serif; font-weight: normal; text-decoration: none; color: #007cb0;">%%=v(@mentionRecipientName)=%%</a> responded to your post on %%=v(@mentionDate)=%%.
                                  </td>
                                </tr>
                              </table>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
 <!-- End script
%%[

else

endif next @i endif

]%%
-->


        <tr>
          <td style="padding: 7px 0 0 0;">
            <table width="560" cellpadding="0" cellspacing="0" borde="0" class="container">
              <tr>
                <td align="center" valign="middle" style="padding:2px 2px 3px 1px; box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.09);" bgcolor="#dfdfdf">
                  <table width="558" class="container" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
                    <tr>
                      <td style="padding:20px 20px 20px 20px; font-size: 14px;" align="left">
                        <table width="508" class="container" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
                          <tr>
                            <td width="508" style="padding: 0 0px 0 0;" class="container" colspan="1" valign="top">
                              <table width="508" class="container" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td align="left" style="font-size: 18px;font-family: 'Roboto Condensed','Helvetica',Arial,sans-serif; font-weight: none; padding:0 0 10px 0; line-height: normal;">
                                    <a href="%%=redirectTo(@mentionTargetURL6)=%%" style="font-size: 18px;color: #000000;text-decoration:none;font-family: 'Roboto Condensed','Helvetica',Arial,sans-serif; font-weight: none; padding:0 0 10px 0; line-height: normal;">%%=v(@mentionPostName6)=%%</a>
                                  </td>
                                </tr>
                                %%[if not empty(@mentionPostBody6) then]%%
                                <tr>
                                  <td align="left" style="font-size: 14px;font-family: 'Roboto Condensed','Helvetica',Arial,sans-serif; font-weight: none; padding:0 0 10px 0; line-height: normal; color: #606060;">
                                    %%=v(@mentionPostBody6)=%% .. <a href="%%=redirectTo(@followedReplyTargetURL6)=%%" target="_blank" style="font-size: 14px;font-family: 'Proxima Nova','Helvetica',Arial,sans-serif; font-weight: normal; text-decoration: none; color: #007cb0;">read more</a>
                                  </td>
                                </tr>
                                %%[endif]%%
                                <tr>
                                  <td align="left" style="padding: 0px 0 0px 0; font-size: 14px;font-family: 'Proxima Nova','Helvetica',Arial,sans-serif; color: #3a3b3c;">
                                    <a href="%%=redirectTo(@mentionActorAccountUrl6)=%%" target="_blank" style="font-size: 14px;font-family: 'Proxima Nova','Helvetica',Arial,sans-serif; font-weight: normal; text-decoration: none; color: #007cb0;">%%=v(@mentionRecipientName)=%%</a> responded to your post on %%=v(@mentionDate)=%%.
                                  </td>
                                </tr>
                              </table>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
 <!-- End script
        <!--End Content -->
        <tr>
          <td align="center" class="mobile-pad-top-20" style="padding: 22px 0 0 0; font-size: 16px;font-family: 'Proxima Nova','Helvetica',Arial,sans-serif; font-weight: none; color: #3a3b3c; line-height: normal;">
            <a href="%%=redirectTo(@mentionUserAccountUrl)=%%" target="_blank" style="font-size: 16px;font-family: 'Proxima Nova','Helvetica',Arial,sans-serif; font-weight: normal; text-decoration: none; color: #007cb0;">
            See all your posts
            </a>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<!-- -->
<!-- -->
<!--END -->
2
  • 4
    Your LookupOrderedRows is set to return 3 rows and if the result returns 3 successful rows then it will loop through 3 times displaying 3 results. I haven't tested your code but visually, this seems to be the case as to why you may be experiencing duplicate sections. Jan 28, 2020 at 4:52
  • 1
    You have the wrong idea how that loop behaves like thechrishaddad already said. You will start rowtimes in that whole stuff. With your next @i you jump at the beginning to the loop. What you want is something like for @i = 1 to @rowCount do IF @i==1 Then ... elseif @i==2 then ... elseif @i==3 then ... else ... endif next @i Jan 28, 2020 at 9:09

2 Answers 2

2

First, I'd recommend not hiding your AMPscript code with HTML comments. That seems to be part of the issue. There are several <!-- opens without --> closes and vice versa.

As it's written, you're going to get the same thing each time since you're overwriting your primary conditional variable values.

set @mentionNotificationType = field(@row,"NotificationType_Mention_1")
set @mentionNotificationType = field(@row,"NotificationType_Mention_2")
set @mentionNotificationType = field(@row,"NotificationType_Mention_3")

Not sure why you have multiple endif next @i endif clauses.

As @Johannes pointed out, you're looping through the result-set but you have code for each of the three cases. I'd recommend adding conditionals for each of the three rows in the resultset as he suggested.

2

Just to include it as answer. You have the wrong idea how that loop behaves like thechrishaddad already said and some of your code does not make sense like @Adam Spriggs said.

What you would like to have is something like this:

for @i = 1 to @rowCount do 
    if @i==1 then
        /* Do Stuff */ 
    elseif @i==2 then 
        /* Do Stuff */  
    elseif @i==3 then
        /* Do Stuff */ 
    else
        /* Do Stuff */ 
    endif 
next @i

Some explanations why your code does not work:

for @i = 1 to @rowCount do 
    /* Do Stuff */
next @i

/* The following code (next i) would never be executed, because the next i call jumps to the beginning of the for loop*/
/* and would probably be even marked as error or warning*/
next @i

Resources:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.