Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If then problem

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
US
My code isn't working properly, I'm trying to display specific html for a specific productid, and standard html for all other product id's. My code isn't working as it is returning the standard html for every product id including my specific one...which is 117.

Here's the code for the If Then statement:
Code:
if rstDisplay("ProductID") = 117 then
	%>
	<td align="center" valign="top" width="25%"><font size="2" face="Arial"><% Response.Write("<a href=""[URL unfurl="true"]www.myurl.com""><img[/URL] border=""0"" src=""images/lightups/""" & rstDisplay("Number") & "s.jpg""></a><br>" & rstDisplay("Name")) %></font></td>
	<%
	else
	%>
	<td align="center" valign="top" width="25%"><font size="2" face="Arial"><% Response.Write("<a href=""products_ny.asp?" & rstDisplay("ProductID") & """>" & "<img border=&quot;0&quot; src=images/newyears/" & rstDisplay("Number") & "s.jpg>" & "</a><br>" & rstDisplay("Name")) %></font></td>
	<%
	end if
	%>

With this code only the second block of html is showing up, even for the record whos ProductID is 117.

Any ideas?
 
Perhaps the ADO field contains a string value "117" instead of a numeric value 117.

If so try this: [tt]if rstDisplay("ProductID") = "117" then[/tt]
 
ProductID is an AutoNumber field in Access. I tried it the way you suggested, but still the same result.

Any other ideas out there?

If it helps, here's the whole of the asp code
Code:
<% 
	Dim rstConn, dbPath
	dbPath = "e:\webs\2612\fpdb\celebrate.mdb"
	Set rstConn = Server.CreateObject("ADODB.Connection")
	rstConn.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath
	set rstDisplay = CreateObject("ADODB.Recordset")
			
			rstDisplay.Open "Select * FROM Products WHERE Category = 'NEW' ORDER BY Name", rstConn
%>
  
<%
	i = 1
	do until rstDisplay.eof
	if not i mod 4 = 0 then
%>
	
	<%
	if rstDisplay("ProductID") = "117" then
	%>
	<td align="center" valign="top" width="25%"><font size="2" face="Arial"><% Response.Write("<a href=""[URL unfurl="true"]http://208.106.197.56""><img[/URL] border=""0"" src=""images/lightups/""" & rstDisplay("Number") & "s.jpg""></a><br>" & rstDisplay("Name")) %></font></td>
	<%
	else
	%>
	<td align="center" valign="top" width="25%"><font size="2" face="Arial"><% Response.Write("<a href=""products_ny.asp?" & rstDisplay("ProductID") & """>" & "<img border=&quot;0&quot; src=images/newyears/" & rstDisplay("Number") & "s.jpg>" & "</a><br>" & rstDisplay("Name")) %></font></td>
	<%
	end if
	%>

<%
	else
%>

	<td align="center" valign="top" width="25%"><font size="2" face="Arial"><% Response.Write("<a href=""products_ny.asp?" & rstDisplay("ProductID") & """>" & "<img border=&quot;0&quot; src=images/newyears/" & rstDisplay("Number") & "s.jpg>" & "</a><br>" & rstDisplay("Name")) %></font></td></tr><tr>

<%
	end if		
	i = i + 1 
	rstDisplay.movenext
	loop
	rstDisplay.Close  
%>
 
Is it possible that 117 has a recordcount evenly divisible by 4? If that were the case then it would actually be going to the third output statement, which is very similar to the second one.

You could make some simple changes to remove that possibility:
Code:
    do until rstDisplay.eof
    [COLOR=red][s]if not i mod 4 = 0 then[/s][/color]
    [COLOR=red][s]%>
    
    <%[/s][/color]
    if rstDisplay("ProductID") = "117" then
    %>
    <td align="center" valign="top" width="25%"><font size="2" face="Arial"><% Response.Write("<a href=""[URL unfurl="true"]http://208.106.197.56""><img[/URL] border=""0"" src=""images/lightups/""" & rstDisplay("Number") & "s.jpg""></a><br>" & rstDisplay("Name")) %></font></td>
    <%
    else
    %>
    <td align="center" valign="top" width="25%"><font size="2" face="Arial"><% Response.Write("<a href=""products_ny.asp?" & rstDisplay("ProductID") & """>" & "<img border=&quot;0&quot; src=images/newyears/" & rstDisplay("Number") & "s.jpg>" & "</a><br>" & rstDisplay("Name")) %></font></td>
    <%
    end if
[COLOR=red][s]    %>
    <%
    else
    %>

    <td align="center" valign="top" width="25%"><font size="2" face="Arial"><% Response.Write("<a href=""products_ny.asp?" & rstDisplay("ProductID") & """>" & "<img border=&quot;0&quot; src=images/newyears/" & rstDisplay("Number") & "s.jpg>" & "</a><br>" & rstDisplay("Name")) %></font></td></tr><tr>

    <%
    end if[/s][/color]

   If i mod 4 = 0 Then
       Response.Write "</tr><tr>"
   End If

Also, it is unnecessary to escape in and out of ASP blocks between sections of code and actually will add the tiniest bit of lag to the page loading. I took out some of the extras.
-T

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top