Jump to content

if and else response.write


kastellu
 Share

Recommended Posts

Hello,I have one problem! This code ( code nubmber 2 )gives me export from DB, but now i would like to say if User is not selected or for example is an empty value of User, make an selection from sql= ="SELECT D, E FROM tblY not the same tbl and:<% do until rs.EOF response.write("<table>") response.write("<td>") response.write("<tr><td>" & rs.fields("D") & "<tr><td>") response.write("<tr><td>" & rs.fields("E") & "</td></tr>") response.write("</td>") response.write("</table>") rs.MoveNext loop%>I tried to use else, but i didn t know how, especialy hot then write response.write. So,... If user have value select from one tbl and give me selected data if not slected ( default ) form second tbl and give data from second tbl in DBCODE number 2

<%User = trim(request("User"))if User<>"" thensql="SELECT A,  B FROM tblX WHERE User ='" & User & "'"set rs=Server.CreateObject("ADODB.Recordset")rs.Open sql,conn%><% do until rs.EOF  response.write("<table>")  response.write("<td>")  response.write("<tr><td>" & rs.fields("User") & "<tr><td>")  response.write("<tr><td>" & rs.fields("A") & "</td></tr>")  response.write("<tr><td>" & rs.fields("B") & "</td>   response.write("</td>")  response.write("</table>") rs.MoveNext loop%><% end if %>

ThanksK

Link to comment
Share on other sites

I tried to use else, but i didn t know how, especialy hot then write response.write. So,... If user have value select from one tbl and give me selected data if not slected ( default ) form second tbl and give data from second tbl in DB
That made my eyes cross.I'm a little confused what you are asking, but this is how you format an if-else statement:
if <condition> then  <statements>else  <statements>end if

Link to comment
Share on other sites

<%country = trim(request("country"))if country<>"" thensql="SELECT Customers FROM Customers WHERE country='" & country & "'"set rs=Server.CreateObject("ADODB.Recordset")rs.Open sql,conn%><table width="100%" cellspacing="0" cellpadding="2" border="1"><tr><th>Customers</th></tr><% do until rs.EOF  response.write("<tr>")  response.write("<td>" & rs.fields("Customers") & "</td>")  response.write("</tr>") rs.MoveNext loop%></table><% end if %>

O.K. this is my example, what i would like to do is that if, ther is no selection in this IF i would like to make ELSE , that would select data from other table in DB

country = trim(request("country"))if country<>"" thensql="SELECT Customers FROM Customers WHERE country='" & country & "'"set rs=Server.CreateObject("ADODB.Recordset")rs.Open sql,conn%><table width="100%" cellspacing="0" cellpadding="2" border="1"><tr><th>Customers</th></tr><% do until rs.EOF  response.write("<tr>")  response.write("<td>" & rs.fields("Customers") & "</td>")  response.write("</tr>") rs.MoveNext loop%><%elsesql="SELECT Distributors FROM Distributors WHERE country='" & country & "'"set rs=Server.CreateObject("ADODB.Recordset")rs.Open sql,conn%><table width="100%" cellspacing="0" cellpadding="2" border="1"><tr><th>Distributors</th></tr><% do until rs.EOF  response.write("<tr>")  response.write("<td>" & rs.fields("Distributors") & "</td>")  response.write("</tr>") rs.MoveNext loop%></table><% end if %>

I made it like this , but no luck, it doesn t wor at all!!! So what do i need to repair?Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...