PHP foreach loop

If I write a query that has multiple  returns, how do I write the foreach loop elsewhere?

<?php
$q  = $this->db->select('*')
					->where('id', $id)
					->where('status', 'open')
					->get('MY-TABLE');
		
$order_item = $q->result_array();

$q->free_result();
		foreach ($q as $row)
		{
$name = $row['name'];
$address = $row['address'];
$birthdate = $row['birthdate'];
}

Open in new window


Lets Say this Query returns three entries.  I want to loop them in a document.
<html>
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi
<?php
[b]LOOP Returns Here:
John Doe 123 Test Lane January 1 2000
Jane Doe 456 Test Lane January 2 2002
Peter Doe 212 Test Lane January 3  2003[/b]
 architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit,
</html>

Open in new window


My Query is much bigger than this and I need to loop different info in different parts of the document
LVL 8
rgranlundAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
After this statement, use var_dump($row); to see what is present in the returned results set.
foreach ($q as $row)

Open in new window

It's a bit of a guess, but I expect that once you have assigned a value to the $q variable you can use that in other places in the script, as long as $q remains in scope.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.