Solved

Asp help urgently

Posted on 2004-03-26
6
197 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

705 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

18 Experts available now in Live!

Get 1:1 Help Now