SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2005
    Location
    London, UK
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    display an image based on array value (loop)

    Hello everyone, hope you're all well.

    Here is my code:

    Code:
    if (!goBook)
    {
        if (V == "*")
        {
            Response.Write(Price("") + " = \n");
    
            if ((Session("ListAttributes"))
            &&  (Session("ListAttributes").length > 0))
            {
                for (var j = 0; j < Session("ListAttributes").length; j++)
                {
                    var aa = String(Session("ListAttributes")[j][0]);
                    %>
    	
    	<table>
    	<tr>
    	<td width="400"><p style="font-family:arial;font-size:10pt;color:#666666;margin-bottom:10px;margin-left:20px;"><% Response.Write(aa + "\n"); %></p>
    
    	<img style="margin-left:20px;margin-bottom:25px;" src="/images/carpic.JPG" width="150" height="90" />
    	
    	</td>
    	
    	<td align="left"><% Response.Write(Price(aa)); %></td>
    	</tr>
    	</table>
    
    
    <%
    
                }
            }
        }
        else
        {
            Response.Write(Price(V));
        }
    
        Response.End();
    }
    It displays 8 different vehicle types and their respective prices, it currently displays like this:

    http://www.londonheathrowcars.com/example.jpg

    What I am trying to do is display a different image for each car type in the loop (eg carpic1, carpic2, carpic3 etc). Having a bit of trouble achieving this, can anyone help?

    Thanks
    Antony

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2005
    Location
    London, UK
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello, just letting you know i got it working via another forum. here is the solution, i just rename my images carpic1, carpic2 etc and it loops through them

    Code:
    if ((Session("ListAttributes")) &&  (Session("ListAttributes").length > 0))
    {
            ImageID = 1
            for (var j = 0; j < Session("ListAttributes").length; j++)
            {
    
              var aa = String(Session("ListAttributes")[j][0]);
     %>
    	
    	<table>
    	<tr>
    	<td width="400"><p style="font-family:arial;font-size:10pt;color:#666666;margin-bottom:10px;margin-left:20px;"><% Response.Write(aa + "\n"); %></p>
    
    	<img style="margin-left:20px;margin-bottom:25px;" src="/images/carpic<%=ImageID%>.JPG" width="150" height="90" />
    	
    	</td>
    	
    	<td align="left"><% Response.Write(Price(aa)); %></td>
    	</tr>
    	</table>
    
    
    <%
    	ImageID = ImageID +1
    
                }
            }
        }
        else
        {
            Response.Write(Price(V));
        }
    
        Response.End();
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •