formatting data extracted from a db

Discussion in 'Programming' started by jbird4k, Mar 27, 2009.

  1. #1
    I have a database table which holds responses from mulitiple online questionnaires, each record represent a question and its response. each instance of a questionnaire is represented by an item_id.

    the customer would like the data from this questionnaire to be displayed in a table format as part of a report.

    the columns names in the display table correspond to the questions not the columns in the response table.


    Below is the code i have tried thus far, the first block works the best but does not repeat the table structure. If any one can come upwith a way for the table structure (row tags) to repeat it will be greatly appreciated.

    
    <cfloop query="getQ75Items"> [COLOR="Red"]<!--- unique item ids associated with questionnaire 75 --->[/COLOR]
    	<cfset row_count = row_count + 1>
    	
    	<cfquery name="getQ75Response" datasource="#application.insp#">
    		select *
    		from response_tbl
    		Where inspection_id = #session.inspection#	and questionaire_id = 75 and item_id = #getQ75Items.item_id#
    	</cfquery> [COLOR="Red"]<!--- query sets up an instance of the questionnaire --->[/COLOR]
    	<!--- <cfoutput >[COLOR="Red"]this code block lays out the data properly, however, the table structure does not repeat[/COLOR]
    		
    			<tr >
    				<td><cfloop query="getQ75Response"><cfif question_id IS 1196 >#response#</cfif></cfloop></td>
    				<td> <cfloop query="getQ75Response"> <cfif question_id IS 1197 >#response#</cfif></cfloop></td>
    				<td> <cfloop query="getQ75Response"> <cfif question_id IS 1198>#response#</cfif></cfloop></td>
    				<td><cfloop query="getQ75Response"><cfif question_id IS 1200>#response#</cfif> </cfloop></td>
    				<td> <cfloop query="getQ75Response"><cfif question_id IS 1201>#response#</cfif></cfloop></td>
    				<td> <cfloop query="getQ75Response"><cfif question_id IS 1202>#response#</cfif></cfloop></td>
    				<td> <cfloop query="getQ75Response"><cfif question_id IS 1554>#response#</cfif></cfloop></td>
    				<td> <cfloop query="getQ75Response"><cfif question_id IS 1555>#response#</cfif> </cfloop> </td>
    			</tr>
    	   
    	
    	</cfoutput> --->
    	
    	
    <!--- 	<cfoutput >[COLOR="DarkOrange"]This code block "stair steps" the data between row 1 - col 1 and Row 8 - col 8 for a single record, and the table structure  does not repeat [/COLOR]
    		<cfloop query="getQ75Response">
    			<tr >
    				<td><cfif question_id IS 1196 >#response#</cfif></td>
    				<td>  <cfif question_id IS 1197 >#response#</cfif></td>
    				<td>  <cfif question_id IS 1198>#response#</cfif></td>
    				<td><cfif question_id IS 1200>#response#</cfif> </td>
    				<td><cfif question_id IS 1201>#response#</cfif></td>
    				<td> <cfif question_id IS 1202>#response#</cfif></td>
    				<td><cfif question_id IS 1554>#response#</cfif></td>
    				<td><cfif question_id IS 1555>#response#</cfif> </td>
    			</tr>
    	   </cfloop>
    	
    	</cfoutput> --->
    	
    	
    	
    	<cfoutput query="getQ75Response">
    		[COLOR="RoyalBlue"]This code block "stair steps" the data between row 1 - col 1 and Row 8 - col 8 for a single record, and the table structure  does not repeat[/COLOR]
    			<tr>
    				<td><cfif question_id IS 1196 >#response#</cfif></td>
    				<td>  <cfif question_id IS 1197 >#response#</cfif></td>
    				<td>  <cfif question_id IS 1198>#response#</cfif></td>
    				<td><cfif question_id IS 1200>#response#</cfif> </td>
    				<td><cfif question_id IS 1201>#response#</cfif></td>
    				<td> <cfif question_id IS 1202>#response#</cfif></td>
    				<td><cfif question_id IS 1554>#response#</cfif></td>
    				<td><cfif question_id IS 1555>#response#</cfif> </td>
    			</tr>
    	   
    	
    	</cfoutput>
    	
    	
    	
    </table>
    </cfloop>
    
    
    
    Code (markup):
     
    jbird4k, Mar 27, 2009 IP