Web Analytics Made Easy -
StatCounter Problems displaying results from a query - CodingForum

Announcement

Collapse
No announcement yet.

Problems displaying results from a query

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems displaying results from a query

    All,

    I'm having problems displaying the results from a query.

    I am building the results from a questionnaire and have 10 questions which have 4 possible answers each (they were radio boxes). What I would like to do is to display the question on the left and the counts of each answer type in the same row - e.g.



    --------------------AT1-----AT2-----AT3-----AT4
    Question 1-------13-------8--------0--------5---

    where AT is the answer type.

    My query is as follows:

    $result = mysql_query("select question_id, answer_type_id count(answer_type_id) as qty from answer GROUP BY question_id, answer_type_id;");

    So this returns a list of question id's, answer_type id's and a count of how many was selected.

    How can I display the data like above?

    if question_id = 1 and answer_type_id = 1 - display results (13)
    if question_id = 1 and answer_type_id = 2 - display results (8)
    if question_id = 1 and answer_type_id = 3 - no results - return 0
    if question_id = 1 and answer_type_id = 4 - display results (5)

    any ideas?

  • #2
    Got a little further - just can't get the correct value for the count now!!

    while ($row = mysql_fetch_array($result)) {
    $result_array[] = $row;
    $question_id = $row[0];
    $answer_type_id = $row[1];
    $count = $row[2];
    }


    if (($question_id = 2) and ($answer_type_id = 2)){
    print $count;
    } else {
    print 0;
    }

    It results the last value in the count array which is 1. When really the answer should be 5. It seems to be ok with the question_id and answer_type_id but I can't return the correct value from the count. If there is no count I would like it to return '0'

    Any ideas?

    Comment


    • #3
      No-one got a clue?

      i'm really stuck on this.....

      any ideas?

      Comment

      Working...
      X