1

I have results of an MySQL query. If I then create an array like:

$List = array();    
do {
  $List[] = $row;
} while($row = $test->fetch_assoc());

When I echo the content I get:

Array ( [0] => [1] => Array ( [SeqID] => SeqID0201 ) [2] => Array ( [SeqID] => SeqID0202 ) [3] => Array ( [SeqID] => SeqID0203 ) ) 

If I then pass the array through a foreach loop

foreach($List as $key => $value) {
    echo $key.' '.$value.'<br />';
}

I get:

1 Array
2 Array
3 Array

My question, how can I get the content of the query result array to pass through the foreach loop to produce the data.

Thanks for your help.

1
  • You have a multidimensional array. $value['SeqID'] is probably what you want. Commented Jul 17, 2016 at 21:15

1 Answer 1

2

You probably want the result of :

foreach($List as $key => $value) {
    echo $key.' '.$value['SeqID'].'<br />';
}
Sign up to request clarification or add additional context in comments.

10 Comments

Perfect. I don't know why I missed that. One last question, how can I get the result in to another array to use in a query, Like $fields[] = $key.' '.$value['SeqID'].'<br />';
Like that: $fields[$key] = $value['SeqID'];?
Hi, all I get is Array ( [] => ) when I print_r
With $fields[$key] = $value['SeqID'] in the foreach?
Hi, this is what I have: foreach($QList as $field => $val) { $fields[$key] = $value['SeqID']; } and when I print_r I get Array ( [] => ). I have tried all manor of combinations with no joy
|

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.