Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is more of a clarification, but as I mentioned in the comments, the alternatives suggested by Steve and Brad differ from <a href="https://stackoverflow.com/a/18616785/104223">the "list approach"</a> in that they require <em>two</em> queries: one to retrieve the id's of the questions to display on the current page, and one to grab the associated answers. </p> <p>There are different ways to implement it, but one option is using a "grouped" output <a href="https://stackoverflow.com/a/18643715/104223">as Steve mentioned</a>. Say you are displaying 10 records per page and want to display results <code>11</code> through <code>20</code>. First run a query to grab the question id's. </p> <pre><code> &lt;!--- For clarity these are descriptive, rather than actual, column names ---&gt; &lt;cfquery name="getCurrentPageQuestions" .....&gt; SELECT QuestionID FROM Questions WHERE SurveyID = &lt;cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.surveyid#"&gt; ORDER BY WhateverColumnsYouWant LIMIT 11, 20 &lt;/cfquery&gt; </code></pre> <p>Next, use those id's to filter your original JOIN. You can skip the filter on survey id because the first query took care of that. </p> <p><em>Important: You <strong>MUST</strong> sort the results by the grouped column first. Otherwise, the grouped cfoutput will not work.</em></p> <pre><code> &lt;cfquery name="getAnswers" .....&gt; SELECT q.QuestionID , q.Question , a.AnswerID , a.Answer , ..... FROM questions q LEFT JOIN answers a ON a.questionID = q.questionID INNER JOIN questiontypes qt ON qt.questionTypeID = q.questionTypeID INNER JOIN surveys s ON s.surveyID = q.surveyID WHERE q.questionID IN ( &lt;cfqueryparam value="#valueList(getCurrentPageQuestions.questionID)#" list="true" cfsqltype="cf_sql_integer"&gt; ) ORDER BY q.questionID &lt;/cfquery&gt; </code></pre> <p>Finally, use Steve's example to display the results in the proper format:</p> <pre><code> &lt;cfouput query="getAnswers" group="questionID"&gt; &lt;!--- display question once ---&gt; #question#&lt;br&gt; &lt;cfoutput&gt; &lt;!--- display all answers ---&gt; - #answer#&lt;br&gt; &lt;/cfoutput&gt; &lt;/cfoutput&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload