0

I am a beginer in AMPscript but eager to learn ! I tried to create dynamic URL thanks to it, it worked well in preview but didn't when sending the email.

Here is my code:

%%[
    set @LAST_STAY_REGION = lookup("CONTACTS2","LAST_STAY_REGION","EMAIL",@EMAIL)        
    set @SAME_REGION = Lookuporderedrows("PRODUCTS","5","SORT_ORDER_FR DESC","REGION_ID",@LAST_STAY_REGION)
]%%

<a target="_blank" href="http://www.name.fr/%%=FIELD(ROW(@SAME_REGION,1), "PACKAGE_ID")=%%">link</a>

So the FIELD(ROW(@SAME_REGION,1), "PACKAGE_ID") will be my variable in my URL. The link works well when I click on it in preview. However when sending it... The AMPscript doesn't work, it just stay like FIELD(ROW(@SAME_REGION,1), "PACKAGE_ID") in the URL

2 Answers 2

1

I'd suggest reviewing the examples on my AMPScript Lookup Examples page.

Here's a version based on what you've provided:

%%[
var @email, @last_stay_region, @same_region, @rows, @row, @rowCount, @numRowsToReturn, @last_stay_region, @i

set @email = AttributeValue("emailaddr")

set @last_stay_region = lookup("contacts2","last_stay_region","email",@email)
set @numRowsToReturn = 0 /* 0 means all, max 2000 */
set @rows = LookupOrderedRows("products",@numRowsToReturn,"SORT_ORDER_FR desc, DEColumn2 asc","region_id", @last_stay_region)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then

for @i = 1 to @rowCount do

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

]%%
  <br>Row %%=v(@i)=%%: <a target="_blank" href="%%=redirectto(concat("http://www.name.fr/",@package_id))=%%">link</a>
%%[

next @i ]%%

%%[ else ]%%

No rows found

%%[ endif ]%%
0

I'd try storing your link in a variable ie. @myvariable and then add it to the href like this:

<a href="%%=redirectto(@myvariable)=%%">CLICK ME</a>

Try this and tell me if it's of any value :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .