0 Replies - 1503 Views - Last Post: 09 May 2005 - 04:06 PM

#1 wiredwizard   User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 76
  • Joined: 07-May 05

codetable

Posted 09 May 2005 - 04:06 PM

Description: use as custom tagcustom tag to buils a quick page that allows you to edit database info great for building admin sections of ecomm sites
<!---
NAME: <codetable>
--->
<!--- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --->
<!--- To Use --->
<!--- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --->
<!--- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --->
<!--- 1. add this page to your custom tags as codetable.cfm --->
<!--- 2. to use: create a blank page and save it as the tableNameYouWantToUse.cfm --->
<!--- 3. call the tag <cf_codetable mydsn="datasourcename" mytable="TableName" mykey="PrimaryKey"> --->
<!--- 4. run the page in your browser --->
<!--- 5. copy the code that is produced to your tableNameYouWantToUse.cfm eracing the call for tag --->
<!--- 6. run the page again in browser customize as needed --->
<!--- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --->
<!--- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --->
<!--- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --->


<!---  attributes --->
<CFPARAM name="Attributes.mydsn" default="changeme">
<CFPARAM name="Attributes.mytable" default="whichtable">
<CFPARAM name="Attributes.mykey" default="primarykey">

<!--- VARIABLES --->
<cfoutput>
<cfset datasourcename = "#Attributes.mydsn#">
<cfset tablename = "#Attributes.mytable#">
<cfset pk_field = "#Attributes.mykey#">
</cfoutput>


<cfquery name="team" datasource="#datasourcename#" dbtype="ODBC">
SELECT *
FROM #tablename#;
</cfquery>
<cfset pk_field = UCase(pk_field)>
<cfset the_fields = team.ColumnList>
<cfset pk_position = ListFInd(the_fields, pk_field)>
<cfset the_fields = ListDeleteAt(the_fields, pk_position)>
<cfset number_columns = ListLen(the_fields)>

<cfparam name="URL.a" default="l">

<cfloop index="x" list="#the_fields#">
<cfoutput><cfparam name="#tablename#.#x#" default=""></cfoutput>

</cfloop>


<cfswitch expression="#URL.a#">

<cfcase value="i">

<cfoutput><cfquery name="insert_#tablename#" datasource="#datasourcename#" dbtype="ODBC">

INSERT INTO #tablename# (
<cfset a = number_columns>
<cfloop index="x" list="#the_fields#">
<cfset a = a -1>
#x#<cfif a GT 0>,</cfif></cfloop>)

VALUES (<cfset a = number_columns>
<cfloop index="x" list="#the_fields#">
<cfset a = a -1>'##FORM.#x###'<cfif a GT 0>,</cfif></cfloop>)

</cfquery></cfoutput>



<cfoutput><cfloop index="x" list="#the_fields#">
<cfset #tablename#.#x# = FORM.#x#>

</cfloop></cfoutput>
</cfcase>


<cfcase value="s">

<cfoutput><cfquery name="#tablename#" datasource="#datasourcename#" dbtype="ODBC">

SELECT * FROM #tablename#

WHERE #pk_field# = ##URL.ID##;
</cfoutput>
</cfquery>

</cfcase>


<cfcase value="u">

<cfoutput><cfquery name="update_#tablename#" datasource="#datasourcename#" dbtype="ODBC">

UPDATE #tablename#

SET 
<cfset a = number_columns>
<cfloop index="x" list="#the_fields#">
<cfset a = a -1>
#x# = '##FORM.#x###'<cfif a GT 0>,</cfif>
</cfloop>
WHERE #pk_field# = ##URL.ID##;

</cfquery>

</cfoutput>

<cfoutput><cfquery name="#tablename#" datasource="#datasourcename#" dbtype="ODBC">

SELECT * FROM #tablename#

WHERE #pk_field# = ##URL.ID##;

</cfquery>

</cfcase>

</cfoutput>

<cfoutput>
<cfcase value="d">

<cfquery name="#tablename#" datasource="#datasourcename#" dbtype="odbc">

SELECT * FROM #tablename#

WHERE #pk_field# = ##URL.ID##;

</cfquery>

<cfquery name="remove_#tablename#" datasource="#datasourcename#" dbtype="odbc">

DELETE FROM #tablename#

WHERE #pk_field# = ##URL.ID##;

</cfquery>

</cfcase>


</cfoutput>

<cfoutput>
<cfcase value="l">

<cfquery name="#tablename#" datasource="#datasourcename#" dbtype="ODBC">

SELECT *

FROM #tablename#;

</cfquery>

</cfcase>

</cfswitch>


</cfoutput>

<cfoutput>
<html>

<head>

<title>CodeTableTemplate</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

</cfoutput>


<cfswitch expression="#URL.a#">

<cfcase value="n,s">

<cfif URL.a IS "N">

     <cfset button_label = "Add">

     <cfset a = "i">

<cfelseif URL.a IS "s">

     <cfset button_label = "Update">

     <cfset a = "u&id=#id#">

</cfif>


<cfoutput>

<form action="<cfoutput>#tablename#</cfoutput>.cfm?a=#a#" method="post"></cfoutput>

  <table border="0" cellpadding="2" cellspacing="0">

<cfoutput>
<cfloop index="x" list="#the_fields#">
   <tr>

      <td align="right">#x#</td>

      <td><input name="#x#" type="text" id="#x#" value="<cfoutput>###tablename#.#x###</cfoutput>"></td>

    </tr>

</cfloop>
</cfoutput>

<tr>

      <Td></Td>

      <Td><cfoutput><input name="" type="submit" value="#button_label#"></cfoutput>

        <cfif URL.a IS "s">

          <cfoutput>

          </td></form>
<td>

          <form action="<cfoutput>#tablename#</cfoutput>.cfm?a=d&id=#URL.ID#" method="post"><input type="submit" value="Delete">
</cfoutput></cfif></Td></form>

</tr>

</table>


</cfcase>



<cfcase value="i,d,u">

     <cfif URL.a IS "i">

          You have just added a record:<br>

     <cfelseif URL.a IS "d">

          YOu have just removed the record:<br>

     <cfelseif URL.a IS "u">

          You have just updated the record:<br>

     </cfif>


<cfoutput>

<cfloop index="x" list="#the_fields#">
<cfoutput>###tablename#.#x###<br>
</cfoutput>
</cfloop>     
</cfoutput>

     
<cfoutput><a href="#tablename#.cfm?a=l">LIST</a>
</cfoutput>
</cfcase>

<cfcase value="l">

<cfoutput>

<form action="<cfoutput>#tablename#</cfoutput>.cfm?a=n" method="post"><input type="submit" value="Add"></form>
</cfoutput>


<table border="1">

<tr>

<cfoutput>
<cfloop index="x" list="#the_fields#">
<td>#x#</td>

</cfloop>
</cfoutput>

</tr>

<cfoutput><cfoutput query="#tablename#"></cfoutput>


<tr>

<cfloop index="x" list="#the_fields#">
<td><cfoutput>###x###</cfoutput></td>
</cfloop>
<td><a href="<cfoutput>#tablename#</cfoutput>.cfm?a=s&id=#<cfoutput>#pk_field#</cfoutput>#">Edit</a></TD>

</tr>

</cfoutput>

</table>


</cfcase>

</cfswitch>

</body>

</html>




Is This A Good Question/Topic? 0
  • +

Page 1 of 1