Solved

Asp help urgently

Posted on 2004-03-26
6
198 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
6 Comments
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 125 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 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now