|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with selecting records in MYSQL
Hello,
I am trying to select sepecific records based on a check box. I am doing this for the admin area of my site. For example they have all the pages listed down below, they can select edit or delete, I have that setup, but now I want to be able to SELECT a SPECIFIC recordset. Like the records for the page home. Structure of menu (tablename: pages) ID (int) (autoincrement) (primary) LINK_NAME (varchar) (50) PAGE_LINK (varchar) (100) SORT_ORDER (varchar) (50) Here is the code I use to create the part where they can select the page to edit. <cfloop query="qGetPages"> <tr> <td height="20" align="left" valign="middle"><cfoutput><a href="#qGetPages.page_link#">#qGetPages.link_name#</a></cfoutput></td> <td align="center" valign="middle"><input name="edit" type="checkbox" id="edit" value="edit"></td> <td align="center" valign="middle"><input name="delete" type="checkbox" id="delete" value="delete"></td> </tr> </cfloop> Here is the part to do the query: <cfif isdefined("go")> <cfif isdefined("form.edit")> </cfif> <cfif isdefined("form.delete")> <!--- This will be the query to delete ---> </cfif> <!--- THis will be the query to edit ---> </cfif> Here is one example record in the db in table pages. ID = 1 LINK_NAME = HOME PAGE_LINK = fuse.cfm?page=home SORT ORDER = 1 Should I add hidden fields with values of the colums, however I still wouldnt know how to do the SQL query. Examples would be greatful. Thank you Much Jordon Bedwell Coldfusion Zone |
|
#2
|
|||
|
|||
|
Return the ID of the page as the checkbox value.
The new code looks like this:
<cfloop query="qGetPages"> <tr> <td height="20" align="left" valign="middle"><cfoutput><a href="#qGetPages.page_link#">#qGetPages.link_name#</a></cfoutput></td> <td align="center" valign="middle"><input name="edit" type="checkbox" id="edit" value="#ID#"></td> <td align="center" valign="middle"><input name="delete" type="checkbox" id="delete" value="#ID#"></td> </tr> </cfloop> This will return FORM.edit and FORM.delete as lists. You can then use cfloop to do your query like so: <cfif isdefined("FORM.edit")> <cfloop index="ID" list="#FORM.edit#"> <cfquery name="edit" datasource="yourdsn"> SELECT * from pages where ID = #ID# </cfquery> </cfloop> </cfif> Remember to replace yourdsn the the name of you datasource. As for your question "I still wouldnt know how to do the SQL query", I would need to know what you are trying to get from the DB. |
|
#3
|
|||
|
|||
|
Also (and I've been saying this a lot lately), I have to point out that this is really basic SQL stuff. It seems like a lot of people are just bypassing their assimilation of SQL knowledge and just trying to leap straight to coding an application. Let me save you a lot of frustration: if this sort of query is giving you trouble, then stop right now and go buy either Ben Forta's "SQL in 10 Minutes" or Ben's "ColdFusion MX Web Application Construction Kit". I'm telling you that without basic SQL knowledge you're not going to be able to do anything and you're constantly going to be bumping into this wall.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Help with selecting records in MYSQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|