www.webdeveloper.com
Results 1 to 9 of 9

Thread: working with databases theory

  1. #1
    Join Date
    May 2003
    Location
    Boston MA USA
    Posts
    25

    working with databases theory

    I'm a little unsure about this. I'm not uber experienced with databases and I just want to make sure I at least understand the concept of what I'm doing.

    So, here it goes. I have a database (it's already been created curtesy of the government) and I'd like to able to allow my visitors to view the information in database. Bear with me, I'm a little hazy on this.

    My question is, Can I create a form and whatever the user inputs would then become the "variables" (for lack of a better word) that I instuct the database to look for? I'm not sure that entirely makes sense, but if needed, I can try to clarigy it.

  2. #2
    Join Date
    Feb 2003
    Location
    Britain
    Posts
    1,335
    That is possible. I can do it with PHP and MySQL, but for ASP, MSSQL etc. you would need someone else.

  3. #3
    Join Date
    May 2003
    Location
    Boston MA USA
    Posts
    25
    Thanks. The Database itself is an Access database. I'm pretty green with the asp stuff here. I'm trying to figure out how to execute the idea of how I want this to work. Thanks for the help! Any other ideas are welcome.

  4. #4
    Join Date
    Feb 2003
    Location
    Britain
    Posts
    1,335
    Your database will have to be converted to a web-ready format. What technologies does your server support?

  5. #5
    Join Date
    Nov 2002
    Location
    Dartmoor [Holiday]
    Posts
    2,382
    You should be able to read an Access database in ASP. Find a tutorial on ASP/databases, and if you have any specific questions post in the ASP forum.

    Adam
    "If youíre not using valid HTML, then you havenít created a Web page. You may have created something else, but it isnít a Web page." - Joe Clark

    Do something amazing (USA) | Make Poverty History

  6. #6
    Join Date
    May 2003
    Location
    Boston MA USA
    Posts
    25
    That was my understanding as well. Since we don't use alot of server technologies across the site, I'm at this point really just determining what goes where. Which pages need what.
    Any recomendations on a asp/datasbase tutorials? I've hit up w3cschools, any other suggestions?

  7. #7
    Join Date
    Nov 2002
    Location
    Dartmoor [Holiday]
    Posts
    2,382
    I use PHP and MySQL so I can't really advise you on ASP tutorials. You could try posting a question in the ASP forum.

    Adam
    "If youíre not using valid HTML, then you havenít created a Web page. You may have created something else, but it isnít a Web page." - Joe Clark

    Do something amazing (USA) | Make Poverty History

  8. #8
    Join Date
    May 2003
    Location
    Boston MA USA
    Posts
    25
    Thanks for the help-I'm going to take the advice because after surfing around I'm even more confused than when I started.

  9. #9
    Join Date
    Jan 2003
    Location
    Jersey Girl
    Posts
    1,198
    hi firegryphon3207...

    I don't know if this will confuse you even more...
    or maybe less

    but anyway... here is a working page that only requires you to plug-in your own Variable name, DB name, Table name, and Field names.
    (the areas that you need to "plug-in" are in bold)

    You will also need to create the page that calls this one (the one that submits the user's form input).

    give this a go and let me know if you can get it to work for you.

    have fun
    k


    <%
    ' this part retrieves the users input from the form and assigns a variable to hold that value

    dim passed_variable
    passed_variable = Request.Form("user_input_from_form")
    %>

    <%
    ' this connection code is styled similarly to the ones used on asp.com (i think).

    openStr = "driver={Microsoft Access Driver (*.mdb)};" & _
    "dbq=" & Server.MapPath("put_the_name_of_your_database_here.mdb")
    Set cn = Server.CreateObject("ADODB.Connection")
    cn.Open openStr

    ' now you need to query the database using SQL and insert the variable as a search criteria.
    ' (note that there is an ORDER BY used here. that would only really apply to queries that...
    ' ... return more than 1 record. just so you know)

    sql = "SELECT name_of_field_1, name_of_field_2, name_of_field_3 " & _
    "FROM name_of_the_table " & _
    "WHERE (name_of_field_1 = '" & passed_variable & "')" & _
    "ORDER BY name_of_field_1;"

    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sql, cn, 3, 3
    %>

    <html>
    <head>
    <title></title>
    </head>
    <body>

    <!-- this part creates a table that is filled with the returned values of the database query -->
    <!-- if the query is based on a unique value (returns only 1 record), this table will work for that -->

    <table border="1">
    <tr>
    <td><b>field_1 Heading</b></td>
    <td><b>field_2 Heading</b></td>
    <td><b>field_3 Heading</b></td>
    </tr>
    <tr>
    <td><% = rs.Fields("name_of_field_1") %></td>
    <td><% = rs.Fields("name_of_field_2") %></td>
    <td><% = rs.Fields("name_of_field_3") %></td>
    </tr>
    </table>

    <br>
    <!-- if the query results will return more than 1 record, this table will work for that -->
    <!-- (although you should realize that this table can also be used to return a single record as well) -->
    <br>

    <table border="1">
    <tr>
    <td><b>field_1 Heading</b></td>
    <td><b>field_2 Heading</b></td>
    <td><b>field_3 Heading</b></td>
    </tr>
    <%
    Do While Not rs.EOF
    %>
    <tr>
    <td><% = rs.Fields("name_of_field_1") %></td>
    <td><% = rs.Fields("name_of_field_2") %></td>
    <td><% = rs.Fields("name_of_field_3") %></td>
    </tr>
    <%
    rs.MoveNext
    Loop
    %>
    </table>
    <%
    ' this part shuts it all down (regardless of which table you use)

    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
    %>

    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles