[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Need Some Help in Deciphering ASP code with a lot of If Then Statements

Asked by coreybryant in Active Server Pages (ASP), Web Languages/Standards

I am trying to re-do the code below some.  Basically I would like to see if some of the <tables> could possibly be removed and center the data as well.

Also, the CatLevel3 (I think) is larger when it appears on the web.  An example of what I started can be found http://www.merchantaccountresources.com/default4.asp - you'll notice (hopefully) that 'Agents / Partners' and 'ISOs / MSPs' are larger than the other categories.

It's still a work in progress but I am stuck on this one page and was hoping that maybe someone could take a look at it.  I fixed one awhile back, but no longer have access to that source code page.  And I am just stuck.

Thanks!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
<table cellpadding="2" width="90%" bgcolor="#808080" border="<% If Instr(Request.ServerVariables("HTTP_USER_AGENT"), "MSIE") Then %>0<% Else %>1<% End If %>">
    <tr>
      <td bgcolor="#FFFFFF">
<%
Function FileFound(FileName)
 Dim FileObj
 FileFound = True
 Set fs = CreateObject("Scripting.FileSystemObject")
 On Error Resume Next
 Set FileObj = fs.OpenTextFile(FileName, 1, False, 0)
 If Err.Number <> 0 Then
  Err.Clear
  FileFound = False
  Exit Function
 End If
 FileObj.Close
 Set fs = Nothing
End Function
	
Set ConnClassified = Server.CreateObject("ADODB.Connection")
ConnClassified.Open ConnectionString
Set cmdTemp = Server.CreateObject("ADODB.Command")
	
If Cat1_ID <> "" Then
	Set CmdCat1Name = Server.CreateObject("ADODB.Recordset")
	cmdTemp.CommandText = "SELECT Cat1_Name FROM Cat1 WHERE (Cat1_ID = " & Cat1_ID & ")"
	cmdTemp.CommandType = 1
	Set cmdTemp.ActiveConnection = ConnClassified
	CmdCat1Name.Open cmdTemp, , 0, 1
	Cat1_Name = CmdCat1Name("Cat1_Name")
	CmdCat1Name.Close
	Set CmdCat1Name = Nothing
End If
	
If Cat2_ID <> "" Then
	Set CmdCat2Name = Server.CreateObject("ADODB.Recordset")
	cmdTemp.CommandText = "SELECT Cat2_Name FROM Cat2 WHERE (Cat2_ID = " & Cat2_ID & ")"
	cmdTemp.CommandType = 1
	Set cmdTemp.ActiveConnection = ConnClassified
	CmdCat2Name.Open cmdTemp, , 0, 1
	Cat2_Name = CmdCat2Name("Cat2_Name")
	CmdCat2Name.Close
	Set CmdCat2Name = Nothing
End If
	
If Cat3_ID <> "" Then
	Set CmdCat3Name = Server.CreateObject("ADODB.Recordset")
	cmdTemp.CommandText = "SELECT Cat3_Name FROM Cat3 WHERE (Cat3_ID = " & Cat3_ID & ")"
	cmdTemp.CommandType = 1
	Set cmdTemp.ActiveConnection = ConnClassified
	CmdCat3Name.Open cmdTemp, , 0, 1
	Cat3_Name = CmdCat3Name("Cat3_Name")
	CmdCat3Name.Close
	Set CmdCat3Name = Nothing
End If
	
If Cat4_ID <> "" Then
	Set CmdCat4Name = Server.CreateObject("ADODB.Recordset")
	cmdTemp.CommandText = "SELECT Cat4_Name FROM Cat4 WHERE (Cat4_ID = " & Cat4_ID & ")"
	cmdTemp.CommandType = 1
	Set cmdTemp.ActiveConnection = ConnClassified
	CmdCat4Name.Open cmdTemp, , 0, 1
	Cat4_Name = CmdCat4Name("Cat4_Name")
	CmdCat4Name.Close
	Set CmdCat4Name = Nothing
End If
	
Set CmdCatNameList = Server.CreateObject("ADODB.Recordset")
	
		If CatLevel = "" Then
			cmdTemp.CommandText = "SELECT Cat1.* FROM Cat1 ORDER BY Cat1_Name"
		ElseIf CatLevel = "2" Then
			cmdTemp.CommandText = "SELECT Cat2.* FROM Cat2 WHERE (Cat1_ID = " & Cat1_ID & ") ORDER BY Cat2_Name"
		ElseIf CatLevel = "3" Then
			cmdTemp.CommandText = "SELECT Cat3.* FROM Cat3 WHERE (Cat2_ID = " & Cat2_ID & ") ORDER BY Cat3_Name"
		ElseIf CatLevel = "4" Then
			cmdTemp.CommandText = "SELECT Cat4.* FROM Cat4 WHERE (Cat3_ID = " & Cat3_ID & ") ORDER BY Cat4_Name"
		End If
	
cmdTemp.CommandType = 1
Set cmdTemp.ActiveConnection = ConnClassified
CmdCatNameList.Open cmdTemp, , 0, 1
%>
<% If CatLevel = "2" Then %>
<br>(<a href="default.asp">Home</a> : <%= Cat1_Name %>)
<% ElseIf CatLevel = "3" Then %>
<br>(<a href="default.asp">Home</a> : <a href="default.asp?CatLevel=2&Cat1_ID=<%= Cat1_ID %>"><%= Cat1_Name %></a> : <%= Cat2_Name %>)
<% ElseIf CatLevel = "4" Then %>
<br>(<a href="default.asp">Home</a> : <a href="default.asp?CatLevel=2&Cat1_ID=<%= Cat1_ID %>"><%= Cat1_Name %></a> : <a href="default.asp?CatLevel=3&Cat1_ID=<%= Cat1_ID %>&Cat2_ID=<%= Cat2_ID %>"><%= Cat2_Name %></a> : <%= Cat3_Name %>)
<% ElseIf CatLevel = "5" Then %>
<br>(<a href="default.asp">Home</a> : <a href="default.asp?CatLevel=2&Cat1_ID=<%= Cat1_ID %>"><%= Cat1_Name %></a> : <a href="default.asp?CatLevel=3&Cat1_ID=<%= Cat1_ID %>&Cat2_ID=<%= Cat2_ID %>"><%= Cat2_Name %></a> : <a href="default.asp?CatLevel=4&Cat1_ID=<%= Cat1_ID %>&Cat2_ID=<%= Cat2_ID %>&Cat3_ID=<%= Cat3_ID %>"><%= Cat3_Name %></a> : <%= Cat4_Name %>)
<% End If %>
 
<% If CatLevel <> "" Then %>
<br><br>
 
<% If FileFound(UploadDirectory & "\Cat1_" & Request("Cat1_ID") & ".jpg") Then %>
	<img width="50" border="0" src="<% =PictureURL %>/Cat1_<%= Request("Cat1_ID") %>.jpg">
 
<% ElseIf FileFound(UploadDirectory & "\Cat1_" & Request("Cat1_ID") & ".gif") Then %>
	<img width="50" border="0" src="<% =PictureURL %>/Cat1_<%= Request("Cat1_ID") %>.gif">
<% End If %>
 
<% End If %>
 
<br>
 
<% TableCounter = 0 %>
 
<table cellpadding="2">
 
<%
If 	DatabaseType = "SQL" Then
	More_Criteria = " And (Ad_Active = 1) AND (Ad_Approved = 1) AND (End_Date >= '" & DATE & "') "
ElseIf DatabaseType = "MSACCESS" Then
	More_Criteria = " And (Ad_Active = 1) AND (Ad_Approved = 1) AND (End_Date >= #" & DATE & "#) "
End IF
	
If Not CmdCatNameList.EOF Then
	
	While Not CmdCatNameList.EOF
	Set CmdCatNumberListings = Server.CreateObject("ADODB.Recordset")
	
		If CatLevel = "" Then
			cmdTemp.CommandText = "SELECT COUNT(Ad_ID) AS SubCount FROM Ads WHERE (Cat1_ID = " & CmdCatNameList("Cat1_ID") & ") " & More_Criteria
		ElseIf CatLevel = "2" Then
			cmdTemp.CommandText = "SELECT COUNT(Ad_ID) AS SubCount FROM Ads WHERE (Cat2_ID = " & CmdCatNameList("Cat2_ID") & ") " & More_Criteria
		ElseIf CatLevel = "3" Then
			cmdTemp.CommandText = "SELECT COUNT(Ad_ID) AS SubCount FROM Ads WHERE (Cat3_ID = " & CmdCatNameList("Cat3_ID") & ") " & More_Criteria
		ElseIf CatLevel = "4" Then
			cmdTemp.CommandText = "SELECT COUNT(Ad_ID) AS SubCount FROM Ads WHERE (Cat4_ID = " & CmdCatNameList("Cat4_ID") & ") " & More_Criteria
		End If
	
	cmdTemp.CommandType = 1
	Set cmdTemp.ActiveConnection = ConnClassified
	CmdCatNumberListings.Open cmdTemp, , 0, 1
%>
 
<% If TableCounter = 0 Then %>
  <tr>
<% End If %>
 
    <td width="225" valign="top"><font face="Comic Sans MS,Arial" size="1">
 
<% TableCounter = TableCounter + 1 %>
 
<% If CatLevel = "" Then %>
 
	<% If CmdCatNameList("Cat1_Image") Then %>
	<a href="default.asp?CatLevel=2&Cat1_ID=<%= CmdCatNameList("Cat1_ID") %>">
	<img width="50" border="0" src="<% =PictureURL %>/Cat1_<%= CmdCatNameList("Cat1_ID") %>.<%= CmdCatNameList("Cat1_Image_Extension") %>" Alt="<%= CmdCatNameList("Cat1_Name") %>">
	</a>
	<% Else %>
	<img border="0" src="images/spacer.gif">
	<% End If %>
 
	<a href="default.asp?CatLevel=2&Cat1_ID=<%= CmdCatNameList("Cat1_ID") %>"><%= CmdCatNameList("Cat1_Name") %>&nbsp;</a>(<%= CmdCatNumberListings("SubCount")%>)
 
<% ElseIf CatLevel = "2" Then %>
 
	<% If CmdCatNameList("Cat2_Image") Then %>
	<a href="default.asp?CatLevel=3&Cat1_ID=<%= Cat1_ID %>&Cat2_ID=<%= CmdCatNameList("Cat2_ID") %>">
	<img width="50" border="0" src="<% =PictureURL %>/Cat2_<%= CmdCatNameList("Cat2_ID") %>.<%= CmdCatNameList("Cat2_Image_Extension") %>" Alt="<%= CmdCatNameList("Cat2_Name") %>">
	</a>
	<% Else %>
	<img border="0" src="images/spacer.gif">
	<% End If %>
 
	<a href="default.asp?CatLevel=3&Cat1_ID=<%= Cat1_ID %>&Cat2_ID=<%= CmdCatNameList("Cat2_ID") %>"><%= CmdCatNameList("Cat2_Name") %>&nbsp;</a>(<%= CmdCatNumberListings("SubCount")%>)
 
<% ElseIf CatLevel = "3" Then %>
 
	<% If CmdCatNameList("Cat3_Image") Then %>
	<a href="default.asp?CatLevel=4&Cat1_ID=<%= Cat1_ID %>&Cat2_ID=<%= Cat2_ID %>&Cat3_ID=<%= CmdCatNameList("Cat3_ID") %>">
	<img width="50" border="0" src="<% =PictureURL %>/Cat3_<%= CmdCatNameList("Cat3_ID") %>.<%= CmdCatNameList("Cat3_Image_Extension") %>" Alt="<%= CmdCatNameList("Cat3_Name") %>">
	</a>
	<% Else %>
	<img border="0" src="images/spacer.gif">
	<% End If %>
 
	<a href="default.asp?CatLevel=4&Cat1_ID=<%= Cat1_ID %>&Cat2_ID=<%= Cat2_ID %>&Cat3_ID=<%= CmdCatNameList("Cat3_ID") %>"><%= CmdCatNameList("Cat3_Name") %>&nbsp;</a>(<%= CmdCatNumberListings("SubCount")%>)
 
<% ElseIf CatLevel = "4" Then %>
 
	<% If CmdCatNameList("Cat4_Image") Then %>
	<a href="default.asp?CatLevel=5&Cat1_ID=<%= Cat1_ID %>&Cat2_ID=<%= Cat2_ID %>&Cat3_ID=<%= Cat3_ID %>&Cat4_ID=<%= CmdCatNameList("Cat4_ID") %>">
	<img width="50" border="0" src="<% =PictureURL %>/Cat4_<%= CmdCatNameList("Cat4_ID") %>.<%= CmdCatNameList("Cat4_Image_Extension") %>" Alt="<%= CmdCatNameList("Cat4_Name") %>">
	</a>
	<% Else %>
	<img border="0" src="images/spacer.gif">
	<% End If %>
 
	<a href="default.asp?CatLevel=5&Cat1_ID=<%= Cat1_ID %>&Cat2_ID=<%= Cat2_ID %>&Cat3_ID=<%= Cat3_ID %>&Cat4_ID=<%= CmdCatNameList("Cat4_ID") %>"><%= CmdCatNameList("Cat4_Name") %>&nbsp;</a>(<%= CmdCatNumberListings("SubCount")%>)
 
<% End If %>
 
<%
Set CmdSubCatNameList = Server.CreateObject("ADODB.Recordset")
	
		If CatLevel = "" Then
			cmdTemp.CommandText = "SELECT Cat2.* FROM Cat2 WHERE (Cat1_ID = " & CmdCatNameList("Cat1_ID") & ")ORDER BY Cat2_Name"
		ElseIf CatLevel = "2" Then
			cmdTemp.CommandText = "SELECT Cat3.* FROM Cat3 WHERE (Cat1_ID = " & Cat1_ID & ") AND (Cat2_ID = " & CmdCatNameList("Cat2_ID") & ") ORDER BY Cat3_Name"
		ElseIf CatLevel = "3" Then
			cmdTemp.CommandText = "SELECT Cat4.* FROM Cat4 WHERE (Cat1_ID = " & Cat1_ID & ") AND (Cat2_ID = " & Cat2_ID & ") AND (Cat3_ID = " & CmdCatNameList("Cat3_ID") & ") ORDER BY Cat4_Name"
		End If
	
cmdTemp.CommandType = 1
Set cmdTemp.ActiveConnection = ConnClassified
CmdSubCatNameList.Open cmdTemp, , 1, 3
	
If Not CmdSubCatNameList.EOF Then
%>
 
 
 
<%
NumberSubCat = o
%>
<table border="0" cellspacing="1">
 
<tr>
 
<td width="0"><img width="50" border="0" src="images/spacer.gif"></td>
 
      <td>
<%
While Not CmdSubCatNameList.EOF And NumberSubCat < 4
%>
<% If CatLevel = "" Then %>
<a href="default.asp?CatLevel=3&Cat1_ID=<%= CmdCatNameList("Cat1_ID") %>&Cat2_ID=<%= CmdSubCatNameList("Cat2_ID") %>"><%= Replace(CmdSubCatNameList("Cat2_Name")," ","&nbsp;") %>&nbsp;</a>&nbsp;
<% ElseIf CatLevel = "2" Then %>
<a href="default.asp?CatLevel=4&Cat1_ID=<%= Cat1_ID %>&Cat2_ID=<%= CmdSubCatNameList("Cat2_ID") %>&Cat3_ID=<%= CmdSubCatNameList("Cat3_ID") %>"><%= Replace(CmdSubCatNameList("Cat3_Name")," ","&nbsp;") %>&nbsp;</a>&nbsp;
<% ElseIf CatLevel = "3" Then %>
<a href="default.asp?CatLevel=5&Cat1_ID=<%= Cat1_ID %>&Cat2_ID=<%= Cat2_ID %>&Cat3_ID=<%= CmdSubCatNameList("Cat3_ID") %>&Cat4_ID=<%= CmdSubCatNameList("Cat4_ID") %>"><%= Replace(CmdSubCatNameList("Cat4_Name")," ","&nbsp;") %>&nbsp;</a>&nbsp;
<% End If %>
<%
NumberSubCat = NumberSubCat + 1
CmdSubCatNameList.MoveNext
Wend
If CmdSubCatNameList.recordCount > 4 Then
%>
...
<% End If %>
 
</td>
    </tr>
  </table>
<%
End If
	
CmdSubCatNameList.Close
Set CmdSubCatNameList = Nothing
%>
 
</font>
 
<br>
	</td>
 
<% If TableCounter = 1 Then %>
<td width="10"></td>
<% End If %>
 
<% If TableCounter = 2 Then %>
  </tr>
<% TableCounter = 0 %>
<% End If %>    
  
 
<%
CmdCatNameList.MoveNext
Wend
	
	CmdCatNumberListings.Close
	Set CmdCatNumberListings = Nothing
%>
 
<% If TableCounter = 1 Then %>
<td width="225" valign="top"></td>
<% End If %>
 
		</table>
 
 
 
 
<%
Else
%>
 
<% If CatLevel <> "5" Then %>
<tr>
<td>
 
	<% If CatLevel = "" Then %>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;No Categories Exist
	<% Else %>
<!-- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;No SubCategories Exist -->
	<% End If %>
 
 
</td>
</tr>
 
<% End If %>
 
		</table>
 
 
 
 
<%
End If
%>
 
 
<%
CmdCatNameList.Close
Set CmdCatNameList = Nothing
%>
 
 
<br>
 
</td>
    </tr>
  </table>
[+][-]08/18/09 02:39 PM, ID: 25127949Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Active Server Pages (ASP), Web Languages/Standards
Sign Up Now!
Solution Provided By: locke_a
Participating Experts: 1
Solution Grade: A
 
[+][-]08/19/09 10:02 AM, ID: 25134888Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625