[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Asp help urgently

Posted on 2004-03-26
6
Medium Priority
?
216 Views
Last Modified: 2011-09-20
dear member,
         I need help in a program of ASP   , in which i have to draw values from two tables (parent and Child) in a tree form and put them in a way that each child record come below its corresponding parent record and next parent record is next in the same row after previous parent record with the same condition as i have told. i have four parent records and each parent record has two child records. i have wrote a code in which i m having some problems this code is giving two record from ist child records and  1 from each later as well as it is also showing one record in child 2 which is actually part of child3.
 sir plz help me i will be very thankful to u.
         i m sending u the code.sir plz remove the error and send me the correct code



<% Option Explicit %>
<html>
<head>
<title>view</title>
</head>
<Body bgcolor="white" >
 
 <%
    dim sql,connect,sql2,i,j,k
      set connect=server.createobject("ADODB.Connection")
      
      connect.open "Hd"
      

      set sql= connect.Execute(_
                 "select dname,ename from dept,emp where dept.deptid=emp.deptid ")%>
 


 <center><h1>ASP Chart</h1></center>
<br><br>
<table bgcolor="#8FA5AB" color="ghostwhite" border="1" cellpadding="0" cellspacing="0" align="center" width="557">
<tr><td><b><center>DG</center><b></td></tr>
</table>      
<br><br><br>

<form name="f1" action="org.asp">
<center>
<table border="1">
<tr>
<%do until sql.eof %>
<%i=1%>    
<td>        
 <b>
          <input type="button" name="b<%=i%>"
value="<%= sql("dname")%>"></b>
<%i=i+1%>
<br><br><br>
<%j=sql("dname")%>

<% while (sql("dname") = j)%>
  <% k=1 %>        
          <input type="button" name="b<%=k%>" value="<%= sql("ename")%>">
            
        <% k=k+1%>    
        <%sql.MoveNext
         wend %>

<br><br><br>
            &nbsp;&nbsp;&nbsp;&nbsp;      
     
</td>      
        <%sql.MoveNext
         loop %>
</tr>
</table>                              
</center>
</form>
                              
                              

                              

</body>
</html>













0
Comment
Question by:leokhan
3 Comments
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 500 total points
ID: 10694041

In the while loop you are not displaying the child node...

<% while (sql("dname") = j)%>
  <% k=1 %>        
          <input type="button" name="b<%=k%>" value="<%= sql("ename")%>">
           <%= sql("ename")% '<-------- added
        <% k=k+1%>    
        <%sql.MoveNext
         wend %>

Also, are dnames and ename are order... your logic works only if they are in order in the database...

There are two ways.
1. load all the records into an array and loop through them to get the child nodes directly.
2. for every dname, query the database again for the childnodes... so there will 2 queries.

I hope I am clear...
venkat.
0
 

Author Comment

by:leokhan
ID: 10697380
thanxs for reply.i will try this first and then tell u about it.
      if u can correct the error then correct it by urself i will be more thankful to u.
0
 
LVL 35

Assisted Solution

by:YZlat
YZlat earned 500 total points
ID: 10704121
This should work. I change your sql statement, added a second sql and removed some extra <% and %>

<% Option Explicit %>
<html>
<head>
<title>view</title>
</head>
<Body bgcolor="white" >
 
 <%
    dim sql,connect,sql2,i,j,k
     set connect=server.createobject("ADODB.Connection")
     
     connect.open "Hd"
     

     set sql= connect.Execute(_
                 "select deptid,dname from dept,emp where dept.deptid=emp.deptid order by dname ")%>
 


 <center><h1>ASP Chart</h1></center>
<br><br>
<table bgcolor="#8FA5AB" color="ghostwhite" border="1" cellpadding="0" cellspacing="0" align="center" width="557">
<tr><td><b><center>DG</center><b></td></tr>
</table>    
<br><br><br>

<form name="f1" action="org.asp">
<center>
<table border="1">
<tr>
<%
if not (sql.eof and rs.bof) then
      do while not sql.eof
            i=1  
            %>
            <td>        
             <b>
                      <input type="button" name="<%=i%>"
            value="<%= sql("dname")%>"></b>
            <%i=i+1%>
            <br><br><br>
            <%
            Dim strSQL="select ename from emp,dept where dept.deptid=" & sql("deptid")
             set sql2= connect.Execute(strSQL)
            if not (sql2.eof and sql2.bof) then
             while not sql2.eof
                     k=1 %>        
                            <input type="button" name="b<%=k%>" value="<%= sql2("ename")%>">
           
                          <% k=k+1    
                         sql2.MoveNext
                     Loop %>

            <br><br><br>
                       &nbsp;&nbsp;&nbsp;&nbsp;      
     
            </td>      
        <%sql.MoveNext
         loop
end if
%>
</tr>
</table>                        
</center>
</form>

</body>
</html>

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question