thefortrees Posted June 20, 2007 Share Posted June 20, 2007 I am creating a survey that pulls questions and responses from a DB. When I query the DB for each question and response from the mysql command line, all the desired data are returned. As soon as the query is implemented into the PHP code below, the first response that should have been retrieved from the DB is not. (There are multiple responses to each question - it does not retrieve the first response for the first question, but all responses after that are retrieved. $query = "SELECT question, response, position FROM questions, responses, survey_instances " . "WHERE questions.questions_id = responses.questions_questions_id " . "AND questions.questions_id = survey_instances.questions_questions_id ORDER BY position"; $result = mysql_query($query); $row = mysql_fetch_array($result); $responses = array(); //Print out questions. If position/question has already been echoed, do not echo again //so that one question is not echoed multiple times. while ($row = mysql_fetch_array($result)){ if ( !in_array($row['question'], $responses) ){ echo "<table>" . "<tr>" . $row['position'] . ") " . $row['question'] . "</tr>" . "<tr><td>" . $row['response'] . "</tr></td>"; $responses[] = $row['question']; } echo "<tr><td>" . $row['response'] . "</td>" . "</table><br>"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.