how to skip first field in DB

Discussion in 'Programming' started by gilgalbiblewheel, Jun 19, 2007.

  1. #1
    How do you make the following skip the first field?
    <%for each x in rs.Fields%>
    Code (markup):

     
    gilgalbiblewheel, Jun 19, 2007 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    instead of enumerating over fields, do an iteration.
    data = rs.getRows()

    for x = 1 to ubound(data,2)
    for y = 0 to 2
    response.write data(y,x)
    next
    next

    or something like that (this is untested) but it grabs and converts your recordset to a 2dim array and iterates over it it - you'll see it starts with 1 instead of 0...
     
    ccoonen, Jun 19, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    <%
    shift(rs.Fields)
    for each x in rs.Fields
    %>
    Code (markup):
    Or add a flag in the for each loop
     
    krt, Jun 19, 2007 IP
  4. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #4
    how does this work?
    what's (data,2)?
     
    gilgalbiblewheel, Jun 19, 2007 IP
  5. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #5
    ubound(Array) gets the upper bounds - the count, of an array.

    ubound(array,2) gets the upper bounds of the first dimension of a 2 dimensional array.
     
    ccoonen, Jun 19, 2007 IP
  6. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #6
    ran into another problem. If the cell ( is that what it's called ) contains no data, the split function which I inserted causes to give an error.

    dim txt,a
    if x.value IsNull then
    	response.write("")
    else
    	txt= x.value
    	a=Split(txt, "&")
    	response.write(a(0) & "<br />")
    	'response.write(a(1))
    end if	
    Code (markup):
     
    gilgalbiblewheel, Jun 19, 2007 IP
  7. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #7
    Use:
    if IsNull(x.value) then
    Code (markup):
     
    krt, Jun 19, 2007 IP
  8. uniqueasitis

    uniqueasitis Peon

    Messages:
    661
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #8
    i think i should learn asp as well. It seems like such an elegant language
     
    uniqueasitis, Jun 20, 2007 IP
  9. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #9
    trim(Value) converts anything to a string... even nulls
     
    ccoonen, Jun 20, 2007 IP
  10. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #10
    For some reason the code is making an extra select field than the number of fields available in the database table and it's giving an error:

    						<%
    						set conn=Server.CreateObject("ADODB.Connection")
    						conn.Provider="Microsoft.Jet.OLEDB.4.0"
    						conn.Open(Server.Mappath("../../kjv.mdb"))
    						set rs = Server.CreateObject("ADODB.recordset")
    						rs.Open "Select * from inssp", conn
    							arrayR = rs.GetRows()				'This has been altered to use an ARRAY. Because we are not putting limits on it (i.e. (8,0), we have made it dynamic AND 2-dimensional
    							maxC = rs.Fields.Count				'This line creates variable maxC, sets it to max fields in database
    							maxR = UBOUND(arrayR,2)				'This line creates variable called maxP, defines it as the upper limit of our array.
    						rs.close
    						conn.close
    						
    [B][COLOR="Red"]						For y=1 to maxR						'Loop through the ARRAY ROWS starting at 0 to the upper limit of our array
    							Response.write("<span class='spokes' id='spoke" & y & "'>Spoke " & y & "<br />")
    							Response.write("<select class='selspokes' id='sp" & y & "'>")
    							For x=0 to maxC				'Loop through the ARRAY COLUMNS starting at 0 to MAX COLUMNs minus 1 (since we are starting at 0)
    
    								
    									'OPTION EXPLICIT
    									dim txt,a
    									If IsNull(arrayR(y,x)) then
    										response.write("")
    									else
    										response.write("<option href='showverse.asp?" & arrayR(y,x) & "'>")									
    										txt= arrayR(y,x) 'x.value
    										a=Split(txt, "&")
    										'response.write(a(0) & " ")
    										'response.write(a(1))
    										
    										'opening the bible table
    										'Opening Database connection
    										set conn2=Server.CreateObject("ADODB.Connection")
    										conn2.Provider="Microsoft.Jet.OLEDB.4.0"
    										conn2.Open(Server.Mappath("../../kjv.mdb"))
    										set rs2 = Server.CreateObject("ADODB.recordset")
    						
    									
    										'This SQL statement creates a list of books
    										SQL2 = "Select * from bible"
    									
    										sql2 = sql2 & " where " & a(0) & " AND " & a(1)
    										rs2.Open sql2,conn2, 1 
    										response.Write(rs2("book_title") & " " & rs2("chapter") )	
    										'response.Write(sql2)
    									
    										rs2.close
    										conn2.close
    										response.Write("</option>")	'Here, instead of p(1,0), we want to use the ARRAY. Also, we are combining the 2 response.write lines together
    									end if	
    								
    								
    								
    							Next
    							Response.write("</select></span><br />")
    						Next[/COLOR][/B]
    						
    						'
    						response.flush						'Flush Response buffer to screen
    						'
    						Erase arrayR
    						Set rs = nothing
    						Set conn = nothing
    						%>
    Code (markup):
     
    gilgalbiblewheel, Jun 22, 2007 IP