Jump to content

How do I pull a specific row from the results of a query AFTER the query is run?


RobertB13

Recommended Posts

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)

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.