?
Solved

Asp help urgently

Posted on 2004-03-26
6
Medium Priority
?
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Suggested Courses

777 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