Skipping one item in the column

Posted by zurna on Stack Overflow See other posts from Stack Overflow or by zurna
Published on 2010-03-30T15:05:46Z Indexed on 2010/03/30 22:33 UTC
Read the original article Hit count: 461

I created a simple news website. I store both videos and images in IMAGES table. Videos added have videos and images added have images stored in a column called ImagesType. Images and Videos attached to a news is stored in ImagesID column of the NEWS table. My problem occurs when I need to display the first image of a news.

i.e.
IMAGES table:

ImagesID ImagesLgURL                        ImagesType  
1        /FLPM/media/videos/0H7T9C0F.flv    videos     
2     /FLPM/media/images/8R5D7M8O.jpg    images  
3        /FLPM/media/images/0E7Q9Z0C.jpg    images  

NEWS table  
NewsID   ImagesID  NewsTitle  
1        1;2;      Street Chic: Paris            ERROR     
2        3;        Paris Runway                  NO ERROR  

The following code give me an error with the 2nd news item because the first ImageID stored in the list is not an image but a video. I need to figure out a way to skip the video item and display the next image.

I hope I made sense.

SQL = "SELECT NEWSID, CATEGORIESID, IMAGESID, NEWSTITLE, NEWSSHORTDESC, NEWSACTIVE, NEWSDATEENTERED"
SQL = SQL & " FROM NEWS N"
SQL = SQL & " WHERE NEWSACTIVE = 1"
SQL = SQL & " ORDER BY NEWSDATEENTERED DESC"
Set objNews = objConn.Execute(SQL)

Do While intLooper1 <= 3 And Not objNews.EOF 

IMAGES =   Split(Left(objNews("IMAGESID"),Len(objNews("IMAGESID"))-1), ";") 

SQL = "SELECT ImagesID, ImagesName, ImagesLgURL, ImagesSmURL, ImagesType"
SQL = SQL & " FROM IMAGES I"
SQL = SQL & " WHERE ImagesID = " & IMAGES(0) & " AND ImagesType = 'images'"
Set objLgImage = objConn.Execute(SQL)

<div>
<a href="?Section=news&SubSection=redirect&NEWSID=<%=objNews("NEWSID")%>">
<img src="<%=objLgImage("ImagesLgURL")%>" alt="<%=objLgImage("ImagesName")%>"  />
</a>
</div>
<%
    objLgImage.Close
    Set objLgImage = Nothing

    intLooper1 = intLooper1 + 1
    objNews.MoveNext 
    Loop
%>

© Stack Overflow or respective owner

Related posts about asp-classic

Related posts about sql-server-2005