Hi, Im trying to set up a site so the admin user can list the contents of any
database using one template, and an argument (code) being passed in the URL
string.
So far all is working fine. It gets the structures table ID and field infor
from the URL code just fine
except I'm struggling getting the actual DATA stored displaying.
Anyone got any tips?
<cfquery name="table_fields" datasource="#datasources.SHOPDSN#">
SELECT *
FROM dbo."_b_table_fields",dbo."_b_table_codes"
WHERE dbo."_b_table_codes".table_code = '#URL.tcd#'
AND dbo."_b_table_fields".table_ID = dbo."_b_table_codes".table_codes_ID
</cfquery>
<cfquery name="table_field_content" datasource="#datasources.SHOPDSN#">
SELECT *
FROM dbo."#table_fields.table_name#"
</cfquery>
<table border="0" cellspacing="0" cellpadding="0" class="admintable">
<!--- DRAW OUT THE FIRST ROW - COLUMN HEADINGS - --->
<tr class="admintable">
<td>Row</td><td class="admintable">-</td>
<cfloop query="table_fields">
<td class="admintable"><cfoutput>#table_fields.field_name#</cfoutput></td>
<td class="admintable">-</td>
</cfloop>
</tr>
<!--- DRAW OUT THE OTHER ROWS --->
<cfset request.rowcounter=1>
<cfloop query="table_fields">
<!--- <tr><td colspan=4>I am starting the row loop</td></tr> --->
<tr>
<td><cfoutput>#request.rowcounter#</cfoutput></td>
<cfloop query="table_field_content">
<!--- GET THE CONTENT FOR EACH ROW IN THE DB Table --->
<cfquery dbtype="query" name="this_row_content" >
SELECT *
FROM table_field_content
WHERE #table_field_content.CurrentRow# = #request.rowcounter#
AND #table_field_content.CurrentRow# = #request.rowcounter#
</cfquery>
<cfloop query="table_fields">
<td colspan=4>data goes here</td>
</cfloop>
</cfloop>
</tr>
<cfset request.rowcounter=request.rowcounter+1>
</cfloop>
</table>
Nightfall_Blue - 30 Aug 2006 11:52 GMT
I've managed to tidy this up a great deal and have fathomed a couple ofd places
where I'm stuck.
The
<cfdump label="row content" var="#this_row_content#">
<cfdump label="cell content" var="#this_cell_content#">
are not working
<cfdump label="row content" var="#this_row_content#"> is outputting all rows
in the query "table_field_content". whereas it was intended to only contain the
single row whose value was set by #request.rowcounter#
<cfdump label="cell content" var="#this_cell_content#"> does the same. In
addition when I want to output it I am going to need to refer to the table
field names (which are in the query "table_fields"), yet I cannot reference
them as the cfloop around the name of the field leaves and extra comma which
creates a syntax error.
Any ideas?
<cfdump label="fields" var="#table_fields#">
<cfdump label="field content" var="#table_field_content#">
<div id="h_spacer_small">. </div>
<div id="pageminusspacer">
<table border="0" cellspacing="0" cellpadding="0" class="admintable">
<!--- DRAW OUT THE FIRST ROW - COLUMN HEADINGS - --->
<tr class="admintable">
<td>Row</td><td class="admintable">-</td>
<cfloop query="table_fields">
<td class="admintable"><cfoutput>#table_fields.field_name#</cfoutput></td>
<td class="admintable">-</td>
</cfloop>
</tr>
<!--- DRAW OUT THE OTHER ROWS --->
<cfset request.rowcounter=1>
<cfloop query="table_field_content">
<!--- GET THE CONTENT FOR EACH ROW IN THE DB Table --->
<cfquery dbtype="query" name="this_row_content" >
SELECT *
FROM table_field_content
WHERE #table_field_content.CurrentRow# = #request.rowcounter#
</cfquery>
<tr class="admintable">
<td><cfoutput>#request.rowcounter#</cfoutput></td><td
class="admintable">-</td>
<cfloop query="table_fields">
<cfquery dbtype="query" name="this_cell_content" >
SELECT *
FROM this_row_content
</cfquery>
<td class="admintable"><cfoutput>this_cell_content</cfoutput></td>
<td class="admintable">-</td>
</cfloop>
</tr>
<cfset request.rowcounter=request.rowcounter+1>
</cfloop>
</table>
<cfdump label="row content" var="#this_row_content#">
<cfdump label="cell content" var="#this_cell_content#">
alexfrates - 30 Aug 2006 16:33 GMT
cfdump will output the entire content of the variable, be it a simple value or
struct.
I would quickly build a database viewer like this:
<cfif isDefined("FORM.submit") and FORM.submit neq ''>
<cfquery name="tb_dump" datasource="#your_datasource#">
SELECT * FROM #FORM.db_tables#
</cfquery>
<cfdump var="#tb_dump#">
<cfelse>
<cfform name="db_dump" format="html" action="">
<cfselect name="db_tables">
<option value="table1">table1</option>
<option value="table2">table2</option>
<option value="table3">table3</option>
<option value="table4">table4</option>
<option value="table5">table5</option>
</cfselect>
<cfinput type="submit" name="submit" value="Do it">
</cfform>
</cfif>
You could dynamically populate the select list from a query also.