0

I am trying to build a table of events on a cloud page. The normal table will remove events with a date that has a past date and this part is working fine.

The issue I am having is, if for some reason there are events within the DE that I'm pulling from but all are out of date, I want a message to say 'no upcoming events'

In messing around with it, i have got the message to display but it loops for the amount of events are in the table. Code below:

%%[
set @audience = "patient"
Set @rows = Lookuporderedrows("Events_table_test",0,"date 
ASC","audience",@audience)
set @rowCount = rowcount(@rows)



for @i = 1 to @rowCount do
SET @CurrentRow = Row(@rows,@i)   
SET @audience = Field(@currentrow,"audience") 
SET @date = Field(@currentrow,"date") 
SET @title = Field(@currentrow,"title") 
SET @location = Field(@currentrow,"location") 
SET @type = Field(@currentrow,"type") 
SET @today = NOW()

set @days = DateDiff(@today, @date, "D")

]%%


%%[if @rowCount > 0 and @days >= 0 then]%%    


<li class="event-listing %%=v(@type)=%% Event pb-4 pt-4">
  <div class="row">
   <div class="col-2">
    <img src="" alt="" class="img-fluid">
  </div>
  <div class="col-10 mt-2">
           <p class="eventDate">%%=v(@date)=%%: %%=v(@location)=%%</p>
              <p class="eventTitle"> . 
 <strong>%%=v(@title)=%% DAYS: %%=v(@days)=%% </strong></p>
                                    </div>
                                </div>
                            </li>
                      </ul>  

                             %%[else]%%
                      NO VALID EVENTS

                           %%[endif
                           next @i]%%
                    </div>
                </div>

1 Answer 1

0

Looks like you reversed your logic. you have the IF inside of your for-loop.

This should work (note how I put the IF statement before the for-loop)

<rest of your ampscript>
SET @today = NOW()
set @days = DateDiff(@today, @date, "D")

if @rowCount > 0 and @days >= 0 then

for @i = 1 to @rowCount do
SET @CurrentRow = Row(@rows,@i)   
SET @audience = Field(@currentrow,"audience") 
SET @date = Field(@currentrow,"date") 
SET @title = Field(@currentrow,"title") 
SET @location = Field(@currentrow,"location") 
SET @type = Field(@currentrow,"type") 


]%%

<rest of your HTML code>

%%[next @i]%%

%%[else]%%
    NO VALID EVENTS

%%[endif]%%

PS: the rest of your file should remain unchanged and still work

PPS: I don't know enough AMPSCRIPT (and I don't have an environment to test it) so I'll delete if this answer makes no sense, but I think this works.

You must log in to answer this question.

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