Link to home
Start Free TrialLog in
Avatar of Coast Line
Coast LineFlag for Canada

asked on

dynamic tr td issues

I am using the following query but the data is coming as:

123
45
678

Here is the below Code i am using

Seems to be OK, but not user what is the Problem:

<cfquery name="qryIA" dbtype="query">
SELECT DISTINCT patientid, sum(total) as total FROM 
    myquery
    group by patientid, total
</cfquery>

  <cfscript>
        if (NOT structKeyExists(form, 'cols')) form.cols = 3;
    </cfscript>
  <cfif qryIA.recordCount MOD form.cols>
    <cfset variables.rows = int(qryIA.recordCount/form.cols) + 1>
    <cfset variables.pads = form.cols - (qryIA.recordCount MOD form.cols)>
    <cfloop from="1" to="#variables.pads#" index="i">
    <cfset temp = queryAddRow(qryIA)>
    <cfset temp = querySetCell(qryIA, 'patientid', '0')>
    </cfloop>
    <cfelse>
    <cfset variables.rows = qryIA.recordCount/form.cols>
  </cfif>
  <cfset variables.thisRow = 1>
  <cfset variables.newrow = false>
  <cfset variables.currentRow = 0>
  <table align="center" border="0" width="100%">
    <tr>
    <cfoutput query="qryIA" group="patientid">
    <cfquery name="qryIA1" dbtype="query">
        SELECT DISTINCT patientid, sum(total) as total FROM
        qryIA
        where patientid = #qryIA.patientid#
        group by patientid, total
       </cfquery>
    <cfif variables.newrow IS true>
      <tr>
    </cfif>
    <td height="30" valign="middle" align="center" style="border:1px dotted ##8471AD;">
    #qryIA1.patientid#<br />
    </td>

    <cfif (qryIA.currentRow MOD form.cols EQ 0) AND (variables.thisROW LT variables.rows)>
      <tr>

      <cfset variables.newrow = true>
      <cfset variables.currentRow = variables.currentRow + 1>
      <cfelse>
      <cfset variables.newrow = false>
    </cfif>
    </cfoutput>
    </tr>

  </table>

Open in new window

Avatar of gdemaria
gdemaria
Flag of United States of America image

I don't see why you need to query inside the loop, it does the same thing as your group-by.  Just add the other CFOUTPUT.

In any case, whether you put the child query back or not, this is the way I would loop your table cells and rows..

 <table align="center" border="0" width="100%">
   <tr>
   <cfoutput query="qryIA" group="patientid">
     <cfoutput>
      <cfif qryIA.currentRow gt 1 and (qryIA.currentRow MOD form.cols EQ 0)>
       </tr><tr>
      </cfif>
       <td height="30" valign="middle" align="center" style="border:1px dotted ##8471AD;">
        #qryIA.patientid#
       </td>
	 </cfoutput>
   </cfoutput>
 </tr>
</table>

Open in new window

Avatar of Coast Line

ASKER

te query inside is required, so cannot change, so replacing ur code will solve or not?
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial