1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help wih Arrays

Discussion in 'C#' started by kifeda, Aug 30, 2006.

  1. #1
    Hello All,

    I'm having some trouble with an array. I'm have three list which I'm trying to insert into a database:

    Here is an example of what the list would look like:
    IngredientID List: 8,8
    QuantityID List: 64,64
    MeasurementID List: 60,60

    As you see, I have three stes of values which I have successfully taken the ingredienIDs, the quantityIDs, and the MeasurementIDs from a drop list and put them in a hidden form. So I have three hidden forms: a form that contains the list of ingredientIDs, one for the list quantityIDs and one for the list of measurementIDs. The list of the ids vary depending on how many ingredients you choose to add to the recipe so if the recipe has 10 ingredients, you would select ten from the first drop down, and then the page would reload to show ten rows of three sets of drop downs. The drop downs are the ingredients (which I take the value ingredientID), the quantity of the ingredient (which I get the quantityID), and the measurement of the ingredient (which I get the measurementID from). The values all go into the hidden forms I mentioned above.

    With me so far? I hope so!

    So the first page is fine, I think. All I want from that page is the correct list of the IDs and I've got that.

    So when you hit submit, it goes to a page I call process.asp and it is supposed to enter the list of IDs into the database at one time. Specifically, if the recipe had ten ingredients, it's supposed to enter 10 rows into the table: one row for each ingredient, and three values: the measurementID, the ingredientID, and the quantityID.

    Here is my code for the process.asp page:
    
    <%@LANGUAGE="VBSCRIPT"%>
    <!--#include file="Connections/ConnStudioApp.asp" -->
    <%
    If Request.Form("submit") = "CONTINUE" Then
    	'read the list of questions
    	listOfIngredients  = Split(Request.Form("ingredientIds"), ",")
    	listOfQuantities = Split(Request.Form("quantities"), ",")
    	
    	For i = 0 to UBound(listOfQuantities)
    			quantity = Request.Form("q_" & listOfQuantities(i))
    	'For i = 0 to Ubound(listofQuantities)
    			'quantity = Request.Form("q_" & listOfQuantities(i))
    	 
    	 author = request.form("author")
    	 
    	 measurement = 9
    	 'quantity = 4
    	 ingredients = 5
    	 
    	 response.write quantity & "<br>"
    		'insert question id and answer into the database
    		insertStmt = "INSERT INTO ingredients_recipes (ingredients, measurement, quantity) values (" & ingredients & "," & measurement & "," & quantity & ");"
    		'objConn.Execute insertStmt
    	'Next
    	Next
    End If
    'Response.Redirect("add_recipe.asp?code=5")
    %>
    
    Code (markup):
    what am I doing wrong? Please help!!!
     
    kifeda, Aug 30, 2006 IP
  2. Mano70

    Mano70 Peon

    Messages:
    42
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What is this:
    Request.Form("q_"

    doing in your array?
     
    Mano70, Aug 31, 2006 IP
  3. BurgerKing

    BurgerKing Active Member

    Messages:
    397
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    58
    #3
    'objConn.Execute insertStmt

    This line appears to be commented out - so it won't do anything. You need to remove the ' character so that this line will execute.

    Of course, you haven't shown the code that initialises objConn (you have to open a connection, etc).
     
    BurgerKing, Aug 31, 2006 IP
  4. Free Born John

    Free Born John Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    so what's not happening? Is it throwing an error or just not inserting. Easiest way to debug this sort of thing is to put a load of response.writes in showing progress through the code and the values of variables such as your sql statement. Once you do that it should become obvious.

    regards

    FBJ
     
    Free Born John, Aug 31, 2006 IP
  5. phd

    phd Active Member

    Messages:
    496
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Use For Each... Next
    instead of
    For i = 0 to UBound(listOfQuantities)
     
    phd, Sep 2, 2006 IP