|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
There is one field in my database
But there are 40, sometimes 100 text fields in my form page. So, can you explain me that how can I use addnew method. Thank you in advance. |
|
#2
|
||||
|
||||
|
What do you need exactly? Do you need to update or insert into the datasbase? And you have 1 field for a database?
First of all: Name all your fields the same except for a different number at the end (a counter) <input type='text' name='name'<%=cnt%> then increment the cnt so that each field will be something like:name1,name2,name3,name4 Then when you need to do the inserts just run a loop for the number of cnt. Let me know if you need more info! |
|
#3
|
|||
|
|||
|
I have 2 field in database
1 - id (autonumber) 2 - title I have 30 fields sometimes 100 fields in my form page (eg. title1, title2, title3, title4........) I need to insert into database Can you explain me with example, how can I run a loop to do insert into database? |
|
#4
|
|||
|
|||
|
I try to do dynamic form.
For example --- There is a question "how many title?" in the first page. --- You will write down "40" --- Then going to appear 40 text fields dynamically. --- You will enter the titles --- When you press submit button..! How can I insert into database? |
|
#5
|
||||
|
||||
|
for i = 1 to cnt
"INSERT INTO TABLENAME (TITLE) VALUES (' " & Request.Form("title"& cnt) & " ')" next |
|
#6
|
||||
|
||||
|
create a hidden field with the number of text fields you have, then set cnt to that hidden field.
<input type='hidden' id='cnt' name='cnt' value='<%=cnt%>'> </input> Good Luck |
|
#7
|
|||
|
|||
|
kurbak ok... me again
![]() one the 1st page you ask how many titles... say you enter 5 (just for brevity's sake). on the next page you read in that value of 5 and store it into a variable ( titleCount = request.form("count") so now you've got 5 stored in titleCount then you use code something like this Code:
<form action="page3.asp" method="post">
<%
titleCount = Request.Form("count")
for i = 1 to titleCount
%>
<input type="textbox" name="title<%=i%>"><br>
<%
next
%>
<input type="hidden" name="count" value="<%=titleCount%>">
<input type="submit" name="submit" value="submit>
ok, now that code would read in the count from a form field "count" on page1.asp and then it would use a For...Next loop in order to dynamically generate the proper amount of fields. now you've got page3.. from page2 you've passed your list of titles as well as a hidden field which tells page3 the number of titles it's going to look for Code:
<%
titleCount = request.form("count")
for i = 1 to titleCount
'here's where it becomes important that you name the dynamically created text boxes on page2 something like "title"
'because you're going to create a string that contains the name of the textbox from page2 and then retreive its value
title = request.form("title" & i)
'use whatever sql code you would use - this will use the variable i as the track number so title 5 from page2 will be put in the database as track 5.
'of course you'll want to use more hidden fields on page2 to pass on the album id and everything (if you're following my advice from the other thread you started)
query = "INSERT INTO Songs (title, trackNumber) VALUES ('" & title & "'," & i & ")"
set rs = con.execute(query)
next
%>
Last edited by unclefu : December 4th, 2003 at 05:16 PM. |
|
#8
|
|||
|
|||
|
I solve my problem. Thank you for your help.
|
|
#9
|
|||
|
|||
|
I have new problems
I have 4 tables first table category (category_id and category name in it) second table artist (artist_id, category_id, artistname in it) third table album (album_id, artist_id, album_title in it) forth table song (song_id, album_id, title in it) I'm selecting category in first page I'm selecting artist in second page I'm selecting album in third page I'm requesting, collecting and posting all id's to the next page. this is the question!! How can I read from database 1- category name when I was selected in first page 2- artist name when I was selected in second page 3- album name when I was selected in third page |
|
#10
|
|||
|
|||
|
ok, so you pass id #4 to page 2
"SELECT name FROM category WHERE category_id = " & id that returns the name of the category "SELECT * FROM artist WHERE category_id = " & id that returns all the artists in that category. then you select an artist and pass on the id of the artist and use "SELECT * FROM album WHERE artist_id = " & id that returns all the albums of that artist... see the pattern? i gotta go to work now, i'll provide more help later (if it's needed). |
|
#11
|
|||
|
|||
|
what am I suppose to do ?
I mean 3 recordset? -----I try what you say like this: Code:
set rs = Server.CreateObject("adodb.recordset")
sqlcat = "SELECT category_name FROM tbl_category WHERE category_id = " & category_id &" " &_
"SELECT * FROM tbl_artist WHERE category_id = " & category_id &" " &_
"SELECT * FROM tbl_album WHERE artist_id = " & artist_id &""
rs.open sqlcat,vb,1,3
------Returned error: Microsoft JET Database Engine (0x80040E14) Syntax error. in query expression 'category_id = 1 SELECT * FROM tbl_artist WHERE category_id = 1 SELECT * FROM tbl_album WHERE artist_id = 1'. |
|
#12
|
|||
|
|||
|
I try before JOIN method
Code:
set rs = Server.CreateObject("adodb.recordset")
sqlcat = "SELECT tbl_category.category_name, tbl_artist.artist_name , tbl_album.album_title " &_
"FROM tbl_category " &_
"INNER JOIN tbl_artist ON tbl_category.category_id = tbl_artist.category_id " &_
"INNER JOIN tbl_album ON tbl_artist.artist_id = tbl_album.artist_id "&_
"WHERE tbl_album.album_id = " & album_id &""
rs.open sqlcat,vb,1,3
--------Returned error Microsoft JET Database Engine (0x80040E14) Syntax error (missing operator) in query expression 'tbl_category.category_id = tbl_artist.category_id INNER JOIN tbl_album ON tbl_artist.artist_id = tbl_album.artist_id'. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > How can I loop while addnew |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|