ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 4th, 2003, 11:11 AM
kurbak kurbak is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Turkey
Posts: 18 kurbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 42 sec
Reputation Power: 0
Question How can I loop while addnew

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.

Reply With Quote
  #2  
Old December 4th, 2003, 01:38 PM
WisconsinGuy's Avatar
WisconsinGuy WisconsinGuy is offline
I thank you very little
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2003
Location: Milwaukee, WI
Posts: 1,028 WisconsinGuy User rank is Corporal (100 - 500 Reputation Level)WisconsinGuy User rank is Corporal (100 - 500 Reputation Level)WisconsinGuy User rank is Corporal (100 - 500 Reputation Level)WisconsinGuy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 35 m 41 sec
Reputation Power: 9
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!

Reply With Quote
  #3  
Old December 4th, 2003, 02:07 PM
kurbak kurbak is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Turkey
Posts: 18 kurbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 42 sec
Reputation Power: 0
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?

Reply With Quote
  #4  
Old December 4th, 2003, 02:22 PM
kurbak kurbak is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Turkey
Posts: 18 kurbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 42 sec
Reputation Power: 0
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?

Reply With Quote
  #5  
Old December 4th, 2003, 02:51 PM
WisconsinGuy's Avatar
WisconsinGuy WisconsinGuy is offline
I thank you very little
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2003
Location: Milwaukee, WI
Posts: 1,028 WisconsinGuy User rank is Corporal (100 - 500 Reputation Level)WisconsinGuy User rank is Corporal (100 - 500 Reputation Level)WisconsinGuy User rank is Corporal (100 - 500 Reputation Level)WisconsinGuy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 35 m 41 sec
Reputation Power: 9
for i = 1 to cnt
"INSERT INTO TABLENAME (TITLE)
VALUES (' " & Request.Form("title"& cnt) & " ')"

next

Reply With Quote
  #6  
Old December 4th, 2003, 02:53 PM
WisconsinGuy's Avatar
WisconsinGuy WisconsinGuy is offline
I thank you very little
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2003
Location: Milwaukee, WI
Posts: 1,028 WisconsinGuy User rank is Corporal (100 - 500 Reputation Level)WisconsinGuy User rank is Corporal (100 - 500 Reputation Level)WisconsinGuy User rank is Corporal (100 - 500 Reputation Level)WisconsinGuy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 35 m 41 sec
Reputation Power: 9
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

Reply With Quote
  #7  
Old December 4th, 2003, 05:14 PM
unclefu unclefu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 120 unclefu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 57 sec
Reputation Power: 6
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.

Reply With Quote
  #8  
Old December 4th, 2003, 09:20 PM
kurbak kurbak is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Turkey
Posts: 18 kurbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 42 sec
Reputation Power: 0
I solve my problem. Thank you for your help.

Reply With Quote
  #9  
Old December 11th, 2003, 08:07 AM
kurbak kurbak is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Turkey
Posts: 18 kurbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 42 sec
Reputation Power: 0
Question My New Problem

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

Reply With Quote
  #10  
Old December 11th, 2003, 08:45 AM
unclefu unclefu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 120 unclefu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 57 sec
Reputation Power: 6
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).

Reply With Quote
  #11  
Old December 11th, 2003, 09:14 AM
kurbak kurbak is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Turkey
Posts: 18 kurbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 42 sec
Reputation Power: 0
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'.

Reply With Quote
  #12  
Old December 11th, 2003, 09:17 AM
kurbak kurbak is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Turkey
Posts: 18 kurbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 42 sec
Reputation Power: 0
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'.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > How can I loop while addnew


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |