0

I have used the following ampscript in Header

%%[
var @rows, @row, @rowCount, @numRowsToReturn, @lookupValue, @i

set @lookupValue = "whee"
set @numRowsToReturn = 0 /* 0 means all */
set @rows = LookupOrderedRows("DataExtensionName",@numRowsToReturn,"DEColumn1 desc, DEColumn2 asc","LookupColumn", @lookupValue)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then

for @i = 1 to @rowCount do

var @DEColumn1, @DEColumn2
set @row = row(@rows,@i) /*get row based on loop counter */
set @DEColumn1 = field(@row,"DEColumn1")
set @DEColumn2 = field(@row,"DEColumn2")

]%%

and then parsing following values in body...

Row %%=v(@i)=%%, DEColumn1 is %%=v(@DEColumn1)=%%, DEColumn2 is %%=v(@DEColumn2)=%%

%%[

next @i ]%%

%%[ else ]%%

No rows found

%%[ endif ]%%

Functionally it's working perfectly fine. But the issue is for every row email is repeating logo and header images?

How do i only repeat values parsed but not logo and header images?

1

From the point where you begin your 'for' loop in the header for @i = 1 to @rowCount do, to the point you put your next @i statement %%[next @i ]%%, will be repeated for the entirety of your for loop.

You should move the AMPScript for loop in your header to just before the part you want repeated. This should solve your issue.

2
  • Thanks, It works. I thought I can not declare the variables in BODY of email. – Sohail Oct 26 '16 at 15:14
  • you can declare and set variables all over, just realize it cascades, so the values you set towards the bottom will override the values you set above – Gortonington Oct 26 '16 at 15:16

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.