RobertB13 Posted August 28, 2012 Share Posted August 28, 2012 Let me try it this way... Database question_id survery_id question_body 1 1 S01 Q01 2 1 S01 Q02 3 2 S02 Q01 4 2 S02 Q02 5 3 S03 Q01 6 3 S03 Q02 $query = 'SELECT * from survey_questions WHERE survey_id = 1'; returns question_id survery_id question_body 1 1 S01 Q01 2 1 S01 Q02 How do I return the array with JUST the information question_id survery_id question_body 1 1 S01 Q01 so I can pull $body = $row['question_body']; //That $body = S01 Q01 Then a 2nd array that JUST question_id survery_id question_body 2 1 S01 Q02 so I can pull $body = $row['question_body']; //That $body = S01 Q02 Not quite sure how to describe what I want to do. Sorry. Thought that mysql_data_seek ($result,0) might have something to do with it and then mysql_fetch_row($result) Quote Link to comment https://forums.phpfreaks.com/topic/267723-how-do-i-pull-a-specific-row-from-the-results-of-a-query-after-the-query-is-run/ Share on other sites More sharing options...
Christian F. Posted August 29, 2012 Share Posted August 29, 2012 You have to loop through the results, and check for the value you want to fetch. No two ways about this, I'm afraid. Though, that said I don't understand why you want it in two different arrays. You can just as easily do the processing on the individual parts in the loop that fetches the data from the DB result. No need to complicate matters further by using unnecessary steps along the way. Quote Link to comment https://forums.phpfreaks.com/topic/267723-how-do-i-pull-a-specific-row-from-the-results-of-a-query-after-the-query-is-run/#findComment-1373441 Share on other sites More sharing options...
Barand Posted August 29, 2012 Share Posted August 29, 2012 Loop through the results and store in an array EG $query = 'SELECT question_id, question_body FROM survey_questions WHERE survey_id = 1'; $questions = array(); $res = mysql_query($query); while ($row = mysql_fetch_assoc($res)) { $questions[$row['question_id']] = $row['question_body']; } echo $questions[1]; //--> S01 Q01 Quote Link to comment https://forums.phpfreaks.com/topic/267723-how-do-i-pull-a-specific-row-from-the-results-of-a-query-after-the-query-is-run/#findComment-1373453 Share on other sites More sharing options...
RobertB13 Posted August 29, 2012 Author Share Posted August 29, 2012 Thank you everyone. Quote Link to comment https://forums.phpfreaks.com/topic/267723-how-do-i-pull-a-specific-row-from-the-results-of-a-query-after-the-query-is-run/#findComment-1373493 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.