0

I have a simple MySQL query, I've checked the query in phpmyadmin and it returns 2 results.

I would like to put the result straight into a session variable which should be fairly easy, i have the code below and i only get the first result.

 $row = mysql_fetch_assoc($get_data);

 $_SESSION['data'] = $row;  

In my head, this should put the result set into the $row variable, but it doesn't contain all the data. Would i need to wrap it in a loop?

1
  • 1
    Yes you have to loop through all the rows Commented Dec 16, 2015 at 13:45

1 Answer 1

2

Each time you call mysql_fetch_assoc it returns one row.

while($row = mysql_fetch_assoc($get_data)) {
    $_SESSION['data'][] = $row;  
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.