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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if then else basically how to do it?????

Status
Not open for further replies.

cazeno

Technical User
Jun 30, 2000
23
DE
k my problem is always the same....1. evrything seems to be rigth and no error is coming up but the whole if loop or also case is ignored
2. an expected statement error message is coming up
here is my code if u can help me would be nice...really

<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<%@LANGUAGE=&quot;VBScript&quot;%>
<!-- #INCLUDE VIRTUAL=&quot;adovbs.inc&quot; -->

<%If Request(&quot;tablename&quot;)=&quot;&quot; Then%>

<title>main</title>
<body bgcolor=&quot;#0066FF&quot; text=&quot;#FFFFFF&quot;>
<p><b><font size=&quot;+2&quot;>Please choose a table you want to display:</font></b></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;b.asp&quot;>
<div align=&quot;center&quot;>
<select name=&quot;tablename&quot; size=&quot;4&quot;>
<option value=&quot;item&quot; selected>item</option>
<option value=&quot;cust&quot; >cust</option>
<option value=&quot;prod&quot; >prod</option>
<option value=&quot;site&quot; >site</option>
</select>
<input type=&quot;submit&quot; name=&quot;Button&quot; value=&quot;Submit&quot;>
</div>
</form>

<%Else

DIM tablename
DIM SQLQuery

tablename = Request.Form(&quot;tablename&quot;)
set myConnection = Server.CreateObject(&quot;ADODB.Connection&quot;)
myConnection.Open &quot;DSN=ph;UID=sa&quot;
SQLQuery = &quot;select * from &quot; & tablename %>

<% If Request.QueryString(SQLQuery)=&quot;select * from item&quot; Then
SQLQuery = &quot;select item_id,descr,serial from item&quot;%>
<% elseif Request(&quot;SQLQuery&quot;)=&quot;select * from cust&quot; Then
SQLQuery = &quot;select cust_id,descr,address,phone from cust&quot;%>
<% elseif Request(&quot;SQLQuery&quot;)=&quot;select * from prod&quot; Then
SQLQuery = &quot;select prod_id,descr from prod&quot;%>
<% elseif Request(&quot;SQLQuery&quot;)=&quot;select * from site&quot; Then
SQLQuery = &quot;select site_id,descr,address from site&quot;%>
<%else%>
nix

<%end if%>
<%end if%>
<%end if%>
<%end if%>

<% set RSTitleList = myConnection.Execute(SQLQuery)%>

<p>&nbsp;</p>
<table cellpadding=2 cellspacing=0 border=0 bordercolor=&quot;#000000&quot; bgcolor=&quot;#FFCCCC&quot;>
<tr bgcolor=&quot;#cccccc&quot;>
<% for each field in RSTitleList.Fields %>
<th><%=field.Name%></th>
<% next %>
</tr>
<% WHILE NOT RSTitleList.EOF %>
<tr>
<% for each field in RSTitleList.Fields %>
<td><small><%=field.Value%></small></td>
<% next %>
</tr>
<%
RSTitleList.MoveNext
Wend
end if
%>
</table>
</head>

caz [sig][/sig]
 
Well, first of all you need to remove some of the asp preprocessor directives (<%...%>). You only need to use these if you want to go back and forth between html and asp. In your if/then/else loop you aren't using any html so the code may just be getting confused. Try this...

Code:
dim sqlQuery
sqlQuery = Request.QueryString(&quot;SQLQuery&quot;)

If sqlQuery=&quot;select * from item&quot; Then
 SQLQuery = &quot;select item_id,descr,serial from item&quot;

 elseif sqlQuery=&quot;select * from cust&quot; Then
  SQLQuery = &quot;select cust_id,descr,address,phone from cust&quot;

  elseif sqlQuery=&quot;select * from prod&quot; Then
   SQLQuery = &quot;select prod_id,descr from prod&quot;

   elseif sqlQuery=&quot;select * from site&quot; Then
    SQLQuery = &quot;select site_id,descr,address from site&quot;
   end if

  end if

 end if        

end if

Notice also the use of but a single call to the request object. This lessens some of the overhead in the asp server.

The use of the case statement should be considered here as it makes use of a more logical construct...

Code:
dim sqlQuery
sqlQuery = Request.QueryString(&quot;SQLQuery&quot;)

Select Case sqlQuery
 Case &quot;select * from item&quot;
  SQLQuery = &quot;select item_id,descr,serial from item&quot;
 Case &quot;select * from cust&quot;
  SQLQuery = &quot;select cust_id,descr,address,phone from cust&quot;
 Case &quot;select * from prod&quot;
  SQLQuery = &quot;select prod_id,descr from prod&quot;
 Case &quot;select * from site&quot;
  SQLQuery = &quot;select site_id,descr,address from site&quot;
 Case Else
  Response.Write &quot;No Match&quot;
End Select

Speaking of case. The SQLQuery in either instance must exactly match (case included) the expression. You may want to consider making each side uppercase ( UCASE(string) ) before evaluation.

Hope this helps, [sig]<p>Rob<br><a href=mailto:robschultz@yahoo.com>robschultz@yahoo.com</a><br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
"Focus on the solution to the problem,<br>
not the obstacles in the way."<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[/sig]
 
i figured this one out .... if you have an if statement and multiple elseif's you only have to end it with a single end if. not like in vb where for each if must be an end if
k it works so .... thx for help anyway
caz [sig][/sig]
 
Ooops. You're right. I know quite a few languages and sometimes get confused on syntax. But, yes, you did figure it out.

Later, [sig]<p>Rob<br><a href=mailto:robschultz@yahoo.com>robschultz@yahoo.com</a><br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
"Focus on the solution to the problem,<br>
not the obstacles in the way."<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[/sig]
 
also, is this right... (im not the greatest no all about code but..)

<%If Request(&quot;tablename&quot;)=&quot;&quot; Then%>

should it be request.form(&quot;tablename&quot;)....

just a guess..

Bye
 
someone,

Request(&quot;xx&quot;) is just a shortcut for Request.Form(&quot;xx&quot;)
so either is applicable.

just a tip! [sig]<p>Jun Nantes<br><a href=mailto:bhudz@junnantes.com>bhudz@junnantes.com</a><br><a href= Nantes Official Internet Site</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top