Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: Just one table

  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Just one table

    Hi. Can someone please help. I tried to modify the the table, in my asp script, please see this.

    Response.Write("<table border=""1"" width=""486"" height=""106"">")

    Response.Write("<tr>")

    Response.Write("<td width=""160"" height=""35""><b>Name</b></td>")

    Response.Write("<td width=""160"" height=""35""><b>Comments</b></td>")

    Response.Write("<td width=""160"" height=""35""><b>Age</b></td>")

    Response.Write("</tr>")

    Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Name") & "</td>")

    Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Comments") & "</td>")

    Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Age") & "</td>")

    Response.Write ("</table>")

    But I don't want it to write a new table each time it reads the database file. Can some try show me how you just update the data in the one table? I wil be happ to post the fulll script of needed
    Kind regards,
    Mike Hughes

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    Response.Write("<table border=""1"" width=""486"" height=""106"">")
    Response.Write("<tr>")
    Response.Write("<td width=""160"" height=""35""><b>Name</b></td>")
    Response.Write("<td width=""160"" height=""35""><b>Comments</b></td>")
    Response.Write("<td width=""160"" height=""35""><b>Age</b></td>")
    Response.Write("</tr>")
    do while not rsGuestbok.EOF
      Response.Write("<tr>")
      Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Name") & "</td>")
      Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Comments") & "</td>")
      Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Age") & "</td>")
      Response.Write("</tr>")
      rsGuestbook.ReadNext
    loop
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Thanks for you help but I'm still have a few probs' can you please help me a bit fuhter? I have gave you all the asp script to see whats happing.

    <html>
    <head>
    <title>Guestbook</title>
    </head>
    <body bgcolor="white" text="black">
    <p><a href="guestbook_form.htm">Back to Form</a> </p>
    <%
    'Dimension variables
    Dim adoCon 'Holds the Database Connection Object
    Dim rsGuestbook 'Holds the recordset for the records in the database
    Dim strSQL 'Holds the SQL query for the database



    'Create an ADO connection odject
    Set adoCon = Server.CreateObject("ADODB.Connection")

    'Set an active connection to the Connection object using a DSN-less connection
    adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")

    'Set an active connection to the Connection object using DSN connection
    'adoCon.Open "DSN=guestbook"

    'Create an ADO recordset object
    Set rsGuestbook = Server.CreateObject("ADODB.Recordset")

    'Initialise the strSQL variable with an SQL statement to query the database
    strSQL = "SELECT tblComments.Name, tblComments.Comments, tblComments.Age FROM tblComments;"

    'Open the recordset with the SQL query
    rsGuestbook.Open strSQL, adoCon

    'Loop through the recordset
    Do While not rsGuestbook.EOF

    'Write the HTML to display the current record in the recordset
    'Response.Write("<table border=""1"" width=""486"" height=""106"">")
    'Response.Write("<tr>")
    'Response.Write("<td width=""160"" height=""35""><b>Name</b></td>")
    'Response.Write("<td width=""160"" height=""35""><b>Comments</b></td>")
    'Response.Write("<td width=""160"" height=""35""><b>Age</b></td>")
    'Response.Write("</tr>")
    'Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Name") & "</td>")
    'Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Comments") & "</td>")
    'Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Age") & "</td>")
    'Response.Write ("</table>")

    Response.Write("<table border=""1"" width=""486"" height=""106"">")
    Response.Write("<tr>")
    Response.Write("<td width=""160"" height=""35""><b>Name</b></td>")
    Response.Write("<td width=""160"" height=""35""><b>Comments</b></td>")
    Response.Write("<td width=""160"" height=""35""><b>Age</b></td>")
    Response.Write("</tr>")
    do while not rsGuestbok.EOF
    Response.Write("<tr>")
    Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Name") & "</td>")
    Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Comments") & "</td>")
    Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Age") & "</td>")
    Response.Write("</tr>")
    Response.Write ("</table>")

    'rsGuestbook.ReadNext
    'loop


    'Move to the next record in the recordset
    rsGuestbook.MoveNext
    Loop

    'Reset server objects
    rsGuestbook.Close
    Set rsGuestbook = Nothing
    Set adoCon = Nothing
    %>
    </body>
    Kind regards,
    Mike Hughes

  • #4
    New Coder
    Join Date
    Jul 2002
    Location
    Los Angeles
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hughesmi, you didn't really describe your problem, but by looking at your code, are still have the same problem of opening your table and closing your table in a loop. Now, you've given yourself 2 loops. I can't recall trying a a loop in a loop with the same recordset before.

    So I've modified your code. Its untested because I don't have your DB.

    Code:
    <html>
    <head>
    <title>Guestbook</title>
    </head>
    <body bgcolor="white" text="black">
    <p><a href="guestbook_form.htm">Back to Form</a> </p>
    <%
    'Dimension variables
    Dim adoCon 'Holds the Database Connection Object
    Dim rsGuestbook 'Holds the recordset for the records in the database
    Dim strSQL 'Holds the SQL query for the database
    
    
    
    'Create an ADO connection odject
    Set adoCon = Server.CreateObject("ADODB.Connection")
    
    'Set an active connection to the Connection object using a DSN-less connection
    adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")
    
    'Set an active connection to the Connection object using DSN connection
    'adoCon.Open "DSN=guestbook"
    
    'Create an ADO recordset object
    Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
    
    'Initialise the strSQL variable with an SQL statement to query the database
    strSQL = "SELECT tblComments.Name, tblComments.Comments, tblComments.Age FROM tblComments;"
    
    'Open the recordset with the SQL query 
    rsGuestbook.Open strSQL, adoCon
    
    'Loop through the recordset, create a loop counter and set to zero
    Dim loopCounter
    loopCounter = 0
    Do While not rsGuestbook.EOF
    
    	'If counter is less than one, but in the loop, start the table and header row
    	If loopCounter < 1 Then
    		Response.Write("<table border=""1"" width=""486"" height=""106"">")
    		Response.Write("<tr>")
    		Response.Write("<td width=""160"" height=""35""><b>Name</b></td>")
    		Response.Write("<td width=""160"" height=""35""><b>Comments</b></td>")
    		Response.Write("<td width=""160"" height=""35""><b>Age</b></td>")
    		Response.Write("</tr>")
    	End If
    
    	'The meat
    	Response.Write("<tr>")
    	Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Name") & "</td>")
    	Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Comments") & "</td>")
    	Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Age") & "</td>")
    	Response.Write("</tr>")
    
    	'Increment the counter
    	loopCounter = loopCounter + 1
    
    	'Move to the next record in the recordset
    	rsGuestbook.MoveNext
    Loop
    If loopCounter > 0 Then	'Logic is if there were records, the counter would have incremented, if greater than zero, close the table
    	Response.Write ("</table>")
    End IF
    
    'Reset server objects
    rsGuestbook.Close
    Set rsGuestbook = Nothing
    Set adoCon = Nothing
    %>
    </body>
    </html>

  • #5
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    I personally would not response.write the entire table but on the variable. It makes the code look cleaner to the eye.

    Just my 2 cents and not helping towards your question.....
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do it cleanly:

    Code:
    <html>
    <head>
    <title>Guestbook</title>
    </head>
    <body bgcolor="white" text="black">
    <p><a href="guestbook_form.htm">Back to Form</a> </p>
    <%
    'Dimension variables
    Dim adoCon 'Holds the Database Connection Object
    Dim rsGuestbook 'Holds the recordset for the records in the database
    Dim strSQL 'Holds the SQL query for the database
    
    
    
    'Create an ADO connection odject
    Set adoCon = Server.CreateObject("ADODB.Connection")
    
    'Set an active connection to the Connection object using a DSN-less connection
    adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")
    
    'Set an active connection to the Connection object using DSN connection
    'adoCon.Open "DSN=guestbook"
    
    'Create an ADO recordset object
    Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
    
    'Initialise the strSQL variable with an SQL statement to query the database
    strSQL = "SELECT tblComments.Name, tblComments.Comments, tblComments.Age FROM tblComments;"
    
    'Open the recordset with the SQL query 
    rsGuestbook.Open strSQL, adoCon
    %>
    <table border="1" width="486" height="106">
    <tr>
    <td width="160" height="35"><b>Name</b></td>
    <td width="160" height="35"><b>Comments</b></td>
    <td width="160" height="35"><b>Age</b></td>
    </tr>
    <%
    'Loop through the recordset
    Do While not rsGuestbook.EOF
    Response.Write("<tr>")
    Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Name") & "</td>")
    Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Comments") & "</td>")
    Response.Write("<td width=""160"" height=""71"">" & rsGuestbook("Age") & "</td>")
    Response.Write("</tr>")
    'Move to the next record in the recordset
    rsGuestbook.MoveNext
    Loop
    
    'Reset server objects
    rsGuestbook.Close
    Set rsGuestbook = Nothing
    Set adoCon = Nothing
    %>
    </table>
    </body>
    </html>
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Thumbs up

    thanks it worsk nice. I just needed a bit of help.
    Kind regards,
    Mike Hughes

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry for the late reply, but you didn't have a closing table row tag in your second table row (or an opening one for that matter!) - just to pinpoint the initial problem with your code since everyone fixed it, but didn't mention it specifically.

    As is often the case, Roy Sinclair's code is a very good approach (although not the only way to do it), and may teach you a few things. I know I've learned a few things from him. Alien51 was pretty much getting at the same thing.

    P.S. Sometimes you can benefit from looking at the generated HTML (i.e. "View Source" in a browser that is looking at the generated webpage) to quickly pinpoint problems like this, as well.
    Last edited by whammy; 12-25-2003 at 03:52 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Yes, thanks all for this I now have all the asp scripts working.

    Just as one final point - do you have any good URLs to show me tips for fixing my little probs? I did look, but nothing that is outstanding.
    Kind regards,
    Mike Hughes

  • #10
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    How would I make the table show just one recored. i,e like a confrimation page?
    Kind regards,
    Mike Hughes

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You'd only pull that record in your SQL Statement. For instance let's say your primary key is called "ID", and you want to pull the record that has an ID of 50 from a querystring:

    http://www.yourwebsite.com/something.asp?ID=50

    would be your link... and then your code would look something like:

    Code:
    <%
    Function ExtractNumbers(ByVal str)
    	If IsNull(str) Then Exit Function
    	Dim enRegEx
    	Set enRegEx = New RegExp
    	enRegEx.Pattern = "\D"
    	enRegEx.Global = True
      	ExtractNumbers = enRegEx.Replace(str,"")
    	Set enRegEx = Nothing
    End Function
    
    Dim ID, SQL, Conn, rs
    
    ID = ExtractNumbers(Request.QueryString("ID"))
    
    SQL = "SELECT * FROM TableName WHERE ID = " & ID
    
    'Put your connection string here
    
    Set rs = Conn.Execute(SQL)
    
    If NOT rs.EOF Then
         'Whatever you want to display here
    Else
         Response.Write("Nothing found!")
    End If
    
    Set rs = Nothing
    Conn.Close
    Set Conn = Nothing
    %>
    I'd definitely learn some SQL if you're going to be using databases, because it's a necessity.

    P.S. That's the reason behind the "ExtractNumbers" function - you want to perform validation on any data you're going to be using in a SQL statement, otherwise your database could be compromised by an unscrupulous person. If you expect a whole number, you definitely want to make sure it _is one_ before using it in your WHERE clause!
    Last edited by whammy; 12-30-2003 at 03:36 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

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