Hello,
I was working on some code, when I ran into this: foreach ($products as $product). One problem, it was not defined. How could this be? Here is the book I got it from: http://english-common.googlecode.com/svn-history/r100/trunk/huyliem/01-Murach.PHP.MySQL/Murach.PHP.and.MySQL.Nov.2010.pdf . It is on 161-163. I don't understand where the $product came from. And one more thing. Doe fetch() turn the mysql variables into arrays? Thanks
vivosmith
27
Newbie Poster
Recommended Answers
Jump to Post@vivosmith
I was working on some code, when I ran into this: foreach ($products as $product). One problem, it was not defined. How could this be?
The link you provided didn't work
so for your example:
foreach ($products as $product)
You can used this:
Jump to PostBasically you're saying to loop through the $products array, and for each element in the array, temporarily make it accessible via the $product variable. Do something with this $product variable, and then loop. This way you have access to a single variable name that you can keep reusing for each …
All 6 Replies
LastMitch
Dani
4,025
The Queen of DaniWeb
Administrator
Featured Poster
Premium Member
vivosmith
27
Newbie Poster
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
vivosmith
27
Newbie Poster
vivosmith
27
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.