Reputation: 7125
I have a PHP page with multiple mysql_query
instances. Almost every one uses a while
loop to retrieve multiple rows of data.
As I keep a snippet of this often used code, and the example I was taught with, used the variable $row
, I have multiple instances of the following on my page:
while ($row = mysql_fetch_assoc($foo_data)) {
$barArray[] = $row['barValue'];
}
I even have an instance of $row = mysql_fetch_assoc($foo_data)
without a while
loop.
I'm wondering if the multiple uses of $row
as a variable on a single page, is all right?
The PHP is functioning fine, but I always want to be sure that my code is proper and conforms to standard rules.
Thank you.
Upvotes: 0
Views: 291
Reputation: 157839
yes, it's all right.
it's all right to use the same spoon when you're eating soup.
Upvotes: 3
Reputation: 9471
Yup, not a problem at all.
Just like always using $i
as your count in a for
loop, you can repeatedly use $row
to no ill effect.
Upvotes: 2
Reputation: 146302
Yes that is fine. but if you try:
var_dump($row);
at the end of your code -- it will only return that last value of $row
Upvotes: 2