#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0

    Display all items in column from database table


    I have a database called ForSale with a column Subject. I want to display all the items under subject on my homepage through ASP only (I can't use PHP).

    I tried this:
    Code:
    set objconn = Server.CreateObject("ADODB.Connection")
    objconn.ConnectionString = "DSN=forsale"
    objconn.Open
      
    Dim strSQL
    strSQL = "SELECT Subject FROM ForSale"
      
    Dim objRS
    set objRS = objConn.Execute(strSQL)
    
    response.write(objRS)
      
    objConn.close
    set objConn = nothing
    But it didn't work as it shoots me an error from response.write(objRS). I am new to ASP and very confused with this atm.
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,424
    Rep Power
    4539
    Here's a place to start your learning http://msdn.microsoft.com/en-us/libr...4%28v=vs.90%29
    You can't response.write an object.
    ======
    Doug G
    ======
    The man who doesn't read good books has no advantage over the man who can't read them.
    --Mark Twain
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0
    Figured it out. And it would have been better if you posted this instead a link to the w3schools ADO page.

    Here's the code for future reference and I also added so it would only display the subjects from the past 14 days (and not the dates too).
    Code:
    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.ConnectionString = "DSN=forsale"
    conn.Open
    
    sql = "SELECT Subject, DatePosted FROM ForSale WHERE ((([DatePosted])<Now()) And (([DateRemove])>Now() Or ([DateRemove]) Is Null)) And ((([Display])=True)) ORDER BY DatePosted DESC"
    
    set rs = conn.execute(sql)
    
    do until rs.EOF
      If rs("DatePosted")> DateAdd("D", -14 , Now) Then 'no posts over 14 days old
    	  dim i
    	  i = 0
    	  for each x in rs.Fields 'loops through both columns (Subject & DatePosted)
    		Response.Write("<li><a href='/ForSale/forsale.asp'>" & x.value & "</a></li>")
    		i = i + 1
    		if i = 1 then exit for 'this is added to keep from displaying the DatePosted column
    	  next
      end if
      rs.MoveNext 'next row
    loop
    
    rs.close
    conn.close
    %>
  6. #4
  7. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,424
    Rep Power
    4539
    And it would have been better if you posted this instead a link to the w3schools ADO page.
    Oh, I didn't realize you just wanted copy & paste code without understanding. Sorry.
    ======
    Doug G
    ======
    The man who doesn't read good books has no advantage over the man who can't read them.
    --Mark Twain
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0
    Originally Posted by Doug G
    Oh, I didn't realize you just wanted copy & paste code without understanding. Sorry.
    From your grumpy comment I realized I must have done something unnecessary in the code. So I looked through it and figured the for loop was stupid of me to add.

    Now my code is:
    Code:
    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.ConnectionString = "DSN=forsale"
    conn.Open
    
    sql = "SELECT Subject, DatePosted FROM ForSale WHERE ((([DatePosted])<Now()) And (([DateRemove])>Now() Or ([DateRemove]) Is Null)) And ((([Display])=True)) ORDER BY DatePosted DESC"
    
    set rs = conn.execute(sql)
    
    do until rs.EOF
      If rs("DatePosted")> DateAdd("D", -14 , Now) Then 'no posts over 14 days old
    		Response.Write("<li><a href=/ForSale/forsale.asp#" & Replace(rs("Subject"), " ", "") & "'>" & rs("Subject") & "</a></li>")
      end if
      rs.MoveNext 'next row
    loop
    
    rs.close
    conn.close
    %>
    Everything in the code (except the do until rs.EOF and the variable names) are mine. I also understand everything in the code. Still grumpy?
  10. #6
  11. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by kaed
    I have a database called ForSale with a column Subject. I want to display all the items under subject on my homepage through ASP only (I can't use PHP).

    I tried this:
    Code:
    set objconn = Server.CreateObject("ADODB.Connection")
    objconn.ConnectionString = "DSN=forsale"
    objconn.Open
      
    Dim strSQL
    strSQL = "SELECT Subject FROM ForSale"
      
    Dim objRS
    set objRS = objConn.Execute(strSQL)
    
    response.write(objRS)
      
    objConn.close
    set objConn = nothing
    But it didn't work as it shoots me an error from response.write(objRS). I am new to ASP and very confused with this atm.
    I am new to ASP and very confused with this atm.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    From your grumpy comment I realized I must have done something unnecessary in the code. So I looked through it and figured the for loop was stupid of me to add.

IMN logo majestic logo threadwatch logo seochat tools logo