Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

From List to database 1

Status
Not open for further replies.

DMAN3021

Programmer
Aug 20, 2002
40
CA
I am building a website on which there will be a dynamicaly populated jump menu. As an administrator, you may edit the jump menu, which is represented as a list on the administartor web page.

I get a problem when I want to take the information in the list and enter it into the database. Every item in the list should be one record in the database, so how do I go about filtering through the list and inserting each item one by one?

Thanks,

Dan...
 
<cfloop list=&quot;#yourLIst#&quot; index=&quot;currentItem&quot;>
<cfquery datasource=&quot;foo&quot; name=&quot;bar&quot;>
INSERT QUERY
</cfquery>
</cfloop>

------------------------------------------------------------------------------
brannonH
if( !succeed ) try( );
 
I've tried that, but I get a &quot;Element is undefined in form&quot; message.

I've written everything right though, no typos or anything...

Also, how do I get the value and text of every item in the list? I would need each items text, value and index.

Any ideas?
 
lets see your code!!

------------------------------------------------------------------------------
brannonH
if( !succeed ) try( );
 
Ok, well, I have my form that contains a list that is populated by my SQL query:

<form method=&quot;POST&quot; action=&quot;<cfoutput>#CurrentPage#</cfoutput>&quot; name=&quot;JumpMenuEdit&quot;>

<select name=&quot;MenuPreview&quot; size=&quot;12&quot; id=&quot;MenuPreview&quot;>
<cfoutput query=&quot;GetJumps&quot;>
<option value=&quot;#GetJumps.JumpID#&quot;>#GetJumps.Name#</option>
</cfoutput>
</select>

<input name=&quot;SaveMenu&quot; type=&quot;submit&quot; id=&quot;SaveMenu&quot; value=&quot;Save&quot;>
</form>

And what I want is to get all items from MenuPreview, and enter them in my database using a SQL Insert, which is what I have here:

<cfquery name=&quot;DeleteCurrentMenu&quot; datasource=&quot;mydata&quot;>
DELETE FROM Menu WHERE (TRUE)
</cfquery>
<cfloop list=&quot;#Form.MenuPreview#&quot; index=&quot;currentItem&quot;>
<cfquery name=&quot;newMenu&quot; datasource=&quot;mydata&quot;>
INSERT INTO Menu (Name, Link,&quot;Order&quot;) VALUES (
'ItemText', 'ItemValue', #currentItem#)
</cfquery>
</cfloop>
 

I am not seeing your application working like that....
Why delete from menu then add all menu items back....

if you have a select set of menu items ( Lets say 10 to be simple )
and you give your administrators the option to add or delete any of these 10 to their custom menu
(let me know if i am on the right track here)

the best way to do something like this is

---------------------------------------------------------
<!--- formpage --->
<form method=&quot;POST&quot; action=&quot;<cfoutput>#actionPage#</cfoutput>&quot; name=&quot;JumpMenuEdit&quot;>
<cfoutput query=&quot;GetJumps&quot;>
<input type=&quot;Checkbox&quot; name=&quot;menuItems&quot; value=&quot;#GetJumps.JumpID#&quot;>#GetJumps.Name#<br>
</cfoutput>
<input type=&quot;Submit&quot; value=&quot;submit&quot;>
</form>


when inserted

<!--- ACTION PAGE --->
<cfloop list=&quot;#Form.menuItems#&quot; index=&quot;currentItem&quot;>
<cfquery name=&quot;newMenu&quot; datasource=&quot;mydata&quot;>
INSERT INTO Menu(
Name,
Link,
&quot;Order&quot;)
VALUES (
'ItemText',
'ItemValue',
#currentItem#)
</cfquery>
</cfloop>

------------------------------------------------------------------------------
brannonH
if( !succeed ) try( );
 
&quot;if you have a select set of menu items and you give your administrators the option to add or delete any of these 10 to their custom menu&quot;

Well, its kinda like that, but the different menu items are not predefined (its a dynamic jump menu on a web site, I want the administrators to be able to specify whatever web site they want as a link.) so the administrators must define what these options are, and cannot select them from a predefined list.

I have build a small javascript/CF app that permits them to enter all of the information they want into a html list (a multiple html select). And now I have to find a way to insert all of the items in that list into my database.

The problems I am getting is getting the list into the database. Thanks to what you posted above, I have almost completed, but now, I find that all items in the list must be selected for the information to be passed on with the form.

Any ideas on how have all items in the list selected before the form is submitted? or on how else I could do this?
 
try this logic.....

<!--- display & add page MAIN.cfm --->
<cfquery datasource=&quot;foo&quot; name=&quot;bar&quot;>
get your menuItems from the database based on the current userAdmin.
</cfquery>

<table>
<tr>
<td>NAME</td>
<td>LINK</td>
<td>DESCRIPTION</td>
<td></td>
</tr>

<cfoutput query=&quot;bar&quot;>
<tr>
<td>#bar.NAME#</td>
<td>#bar.LINK#</td>
<td>#bar.DESCRIPTION#</td>
<td><a href=&quot;delete.cfm?item=#bar.linkID#&quot;</td>
</tr>
</cfoutput>
</table>
<form action=&quot;insertPage.cfm&quot;>
name: <input type=&quot;Text&quot; name=&quot;name&quot;><br>
type=&quot;Text&quot; name=&quot;link&quot;><br>
description<br>
<textarea name=&quot;description&quot;></textarea>
</form>

---------------------------------------------------------------
<!--- insertPage.cfm --->
<cfquery name=&quot;insert&quot; datasource=&quot;foo&quot;>
insert into tablename(
link,
name,
description)
VALUES(
#form.link#,
#form.name#,
#form.description#)
</cfquery>
<cflocation addtoken=&quot;No&quot; url=&quot;MAIN.cfm&quot;>

-------------------------------------------------------------------
<!--- delete.cfm --->
<cfquery name=&quot;insert&quot; datasource=&quot;foo&quot;>
delete from tablename where linkid = <cfqueryparam cfsqltype=&quot;CF_SQL_NUMERIC&quot; value=&quot;#url.item#&quot;>
</cfquery>
<cflocation addtoken=&quot;No&quot; url=&quot;MAIN.cfm&quot;>

----------------------------------------------------------------------------

------------------------------------------------------------------------------
brannonH
if( !succeed ) try( );
 
Well, after a whole lot of work and pondering, I was able to get a good mix of both JS and CF together to create an editable menu on one page.

Thanks for all the help, very usefull!

Dan...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top