View Single Post
 
Old July 31st, 2003, 01:13 PM
tcasp tcasp is offline
Registered User
 
Join Date: Jul 2003
Location: , NY, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to tcasp
Default Search using drop down list box and a text box

I am trying to search database using drop down list box and a text box from two database tables with a submit button
table1= MainCategories like technology,internet with ids 10,20 and etc.
table2=subCategories like category=technology,title=web developer,id=10
again same but tile is programmer and id is 10 and etc
u will select category from database driven list box and u will enter key word like web developer
as a result it should display all matching records from the two tables but I have prob it displays every record ,so I need help.
Thank you .
When I try with inner join it shows all the records
when I use "&id&" ,it gives me an error message "object required"
I am not sure where I am making mistake ?

Here is code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>Drop Down List box</title>


<script language="javascript">

    function go()
        {


         if(document.frm1.s1.options[document.frm1.s1.selectedIndex].value=="ww" )
        

             {
            
                 alert("You did not make any selection,enter search key word,so try again?");
                return false;

             }
            
                 if (frm1.title.value == "")//if text box is empty
                 {
                     alert("You did not ,enter search key word,so try again?");
                     document.frm1.title.focus();
                 return false();

                 }
         else
                document.frm1.catid.value=
                document.frm1.s1.options[document.frm1.s1.selectedIndex].value

             document.frm1.submit();
                return true;
     }
    
    

</script>

</head>

<body>
<%
            
         Dim Conn,RS,sSQL,catid,category,title
    

         Set Conn = Server.createobject("Adodb.connection")
         Set RS = Server.CreateObject ("ADODB.Recordset")
        ' Conn.Open ("DSN=test")
         Conn.Open ("DSN=tariqch;UID=administrator;PWD=admin") 'for sql Server database
         sSQL = " Select catid,category from tblcategory "
         Set RS = Conn.execute(sSQL)

    %>

    <center>

    <form name ="frm1" action="test1.asp" method="post">


     <table height="20%" width="20">
         <Input type="hidden" Name="catid" Value="<%=rs("catid")%>">

            <tr>
             <td>
            <Select Name="s1">

                <option value="ww" Selected>---Make a Selection----</option>
    
                    <%Do While Not rs.EOF %>
    
                         <option Value="<%=rs("catid")%>"><%=rs("category")%>

                        
             <%
                     rs.moveNext
                        Loop
                     rs.close
                    Set rs =nothing
                 %>
    
                 </Select></td>
             </tr>
             <tr>
                     <td>
                         <Input type="text" Name="title" size="15"></td>
                    </tr>
             <tr> <td>
                <input type="button" Value=" Search " Name="btnsub" onClick="go();">
                <input type="reset" Value=" Clear " Name="Reset">
                </td>
                 </tr>
         </table>
    </form>
</center>

</body>
</html>

%@ Language=VBScript %>
<HTML>
<HEAD>
</HEAD>
<BODY background="bg.jpg">

<%
    
    catid= Request.form("catid")

    category= Request.Form("category")
    
     title=Request.Form("title")
     description =Request.Form("description")
    
     Dim conn,sSQL,Rs,catid,subcatid

    Set conn = Server.createobject("AdoDB.connection")
    Set RS = Server.CreateObject ("ADODB.Recordset")
    Conn.Open ("DSN=test;UID=administrator;PWD=admin")

     'Conn.open ("DSN=tariqch")
    

    

sSQL ="Select tblcategory.category,tblsubcat.title,tblsubcat.des cription from tblcategory,tblsubcat Where tblcategory.catid = "&tblsubcat.catid&" "
            
        
    Set RS = conn.execute(sSQL)

%>

    <center><table border="4" cellspacing=2 cellpadding=2>
                
                    <tr bgcolor="yellow">
                        <td><b>Category</b></td>
                        <td><b>title</b></td>
                        <td><b>Description</b></td>

                    </tr>

<% While NOT rs.EOF %>

                    <tr>
                        <td> <%=rs("category") %></td>
                        <td> <%=rs("title") %></td>
                        <td> <%=rs("Description") %></td>
                            
                    </tr>


     <%
                rs.MoveNext
            Wend
    
        rs.close
        conn.Close
        Set rs = Nothing
        Set conn = Nothing
    
     %>

    
            </table>
             </Center>
</BODY>
</HTML>