I'm trying to pull info from a reference table into a landing page. Essentially the table is 2 fields, PromoCode & Description. This table will be updated on a regular basis and at the moment has 10 rows in it but that will increase over time. Is there a way to do a loop and a lookup in AMPScript when there's no primary key to match the data to in order to display the info in a landing page?

So it will display:

PromoCode1 Description1

All the way down to PromoCoade10, Description10. But when an 11th gets added into the table, the landing page automatically adds it in?

1 Answer 1


To clarify, you don't need a Primary Key when using LookupRows or LookupOrderedRows, but you do need a column in your data to match rows against (which has to be an exact match). This is a little frustrating, but the workaround is simple enough.

Create a new field in your DE named 'Display'. Make this a nullable field with a boolean type and a default value of 'True'. Then use the following code in your landing page, replacing PromotionsDE with the name of your Data Extension:

<!DOCTYPE html>

table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 400px;

td, th {
    font-family: arial, sans-serif;
    border: 1px solid #dddddd;
    text-align: left;
    padding: 8px;

tr:nth-child(even) {
    background-color: #dddddd;
    <th>Promo Code</th>

var @rows, @rowcount

set @rows = LookupRows('PromotionsDE','Display', 1)
set @rowcount = RowCount(@rows)

if @rowcount > 0 then

var @i
for @i = 1 to @rowcount do

var @promocode, @description, @row
set @row = Row(@rows,@i) 
set @promocode = Field(@row,"PromoCode")
set @description = Field(@row,"Description")


%%[ next @i ]%%

%%[ else ]%%

 <tr><td colspan="3">No rows found.</td></tr>

%%[ endif ]%% 


This page will render the following HTML:

FYI, if you ever have a need to hide specific DE rows from appearing in the table, then you can just add the 'Display' field to false.

  • That's good to hear. Please feel free to accept my answer for the benefit of others. Apr 11, 2017 at 10:35

You must log in to answer this question.

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