![]() |
|
Don't ask to ask, just ask | |
PerlMonks |
Mysterious Code "DBI" - Why is this working?by awohld (Hermit) |
on Jun 09, 2005 at 02:49 UTC ( #464938=perlquestion: print w/replies, xml ) | Need Help?? |
awohld has asked for the wisdom of the Perl Monks concerning the following question:
This code takes all the "Distinct" entries in a DB column and puts them in a drop down select HTML form field. Here is my code: Originally I had "my @market = $market_sth->fetchrow_array;" in there because I wanted to store the entire DB fetch in an array, then print it. I didn't know what I was doing and this is wrong. As you can see from my code I ended up using a "while" statement to fetch each row and then print one at a time. So when I delete "my @market = $market_sth->fetchrow_array; ", since it's code that doesn't do anything, my "while ($market = $market_sth->fetchrow_array)" breaks and nothing prints out. Even when I rename "my @market = $market_sth->fetchrow_array;" to "my @market_crazy_name = $market_sth->fetchrow_array;" nothing changes! Why doesn't any of the DB fetch print in the HTML drop down box with the "my @market = $market_sth->fetchrow_array;" code removed? What the HECK! UPDATE: When I change "while ($market = $market_sth->fetchrow_array)" to "while (@market = $market_sth->fetchrow_array)" and delete "my @market = $market_sth->fetchrow_array;" everything works!. Now my question is: Why does this work? And this doesn't What's so special about assigning the first $market_sth->fetchrow_array to @any_array, that it will later let me fetch each row to a scalar?
Back to
Seekers of Perl Wisdom
|
|