![]() |
help with cfquery for update!
i couldn't update my database because everything is populated to an uncertain amount of rows of data with the same project name. why is it uncertain amount because this is depending on how many requested has being made to this project. let say i have a project named MTM and there are 6 requests been make to this project, therefore it will populate 6 times like this:
----------------------------------------------------------- request| project name|Number|date|--time--|---update-- ----------------------------------------------------------- --1----|---- MTM--- |123456|4 Apr|2:15 PM|buttonUpdate --2----|---- MTM--- |457446|3 Apr|2:30 PM|buttonUpdate --3----|---- MTM--- |452741|2 Apr|2:20 PM|buttonUpdate --4----|---- MTM--- |234534|5 Apr|3:15 PM|buttonUpdate --5----|---- MTM--- |123414|4 Apr|2:45 PM|buttonUpdate --6----|---- MTM--- |124143|3 Apr|4:15 PM|buttonUpdate after user edit the txt field number user will click on update button. this is my SQL and the cause of the problem: <cfquery datasource="DBcadcam"> UPDATE table1 SET Number='#form.txtnumber#' WHERE ProjectName=#ProjectName# </cfquery> the WHERE clause will give me all the 6: ProjectName=MTM,MTM,MTM,MTM,MTM,MTM how can i make my submit button recognize which row it is submitting? just thought of this after typing so much ... |
Ok, you must be having all of the form fields in one single form. You are getting that comma delimited list of field values because you have 6 form fields all named with the same name: "projectName". Basically, if there are multiple form fields with the same name, ColdFusion takes their values and makes a list out of them when they are submitted.
Probably the easiest thing to do is to create a completely separate form for each row. Each form would only hold the fields of a particular row, and therefore the update button would only submit those particular form fields to your save page. Try that out and let me know how it goes. I'm just thinking tho, if you are using an html table, it might not result in valid markup with surrounding <tr> tags with <form> tags. So if that method doesn't work, we can either implement a solution by appending a row number to each form field, or using JavaScript to submit exactly what we want. Let me know though, and post your code too if you can btw. -Greg |
Quote:
all this code is scanned, hope is not difficult to read.. update.cfm Code:
<!--- update.cfm --->Code:
<!--- updateAction.cfm ---> |
Dude, you're killing me here with the scans... Next time you scan something, please format it with the proper code-readable indentation, and correct any of the errors that might have come up from the OCR software.
Here's an example of what the code would look like properly indented, in a readable form: Code:
<!--- update.cfm --->By the way, why don't you just download ColdFusion server onto your local computer, and use it as a development server? (Instead of relying on using a computer that doesn't have access to the internet.) That's how I do all of my development. The developer edition of CF server is free, and if you have Windows xp/vista/7 professional edition, you can use IIS as the local web server. (Otherwise you'll need to use Apache or something else as the web server.) Just remember to install a web server before installing ColdFusion (as you'll need to tell the ColdFusion installer which one you're using). Just a few notes on code style btw: 1) Variable names should start with a lowercase letter. The only names that should really start with an uppercase letter is a class name (ColdFusion component). 2) It can make your code much more readable to prefix outputted query columns with the name of the query. For example, use #DIRdata.projectName# instead of just #projectName#. This makes it clear that the variable is coming from a query, and isn't just a regular variable that was set somewhere earlier in the code. Here is a JavaScript solution to your problem. This grabs all of the input elements out of a table row (input's, select's, and textarea's - if you have any in the future), and populates a separate form with them. That form is then submitted, and you end up only submitting the data that was in your table row. Notice that there is no longer a form surrounding the table itself. Code:
<!--- update.cfm --->Try that and let me know how it goes. -Greg |
Thanks for the tips on how to name the variables and the solution! and sorry man next time i will edit it into a readable format =).
Quote:
|
Wow, weird company... lol. But alright, whatever works! Haha.
-Greg |
thanks my program is updating now =)
|
| All times are GMT +1. The time now is 03:56 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.