Rows not being returned ?

S

Sylvie Stone

Hi Group!

Can someone PLEASE tell me why this is not returning the $one variable
?
I'l pulling results from a survey database table where the answers was
a range from 1 - 10. This is howe I'm unsuccessfully printing the
results:

my @numbers = (["0"],["1"],
["2"],["3"],["4"],["5"],["6"],["7"],["8"],["9"],["10"]);
my $sth = $dbh->prepare('select count(*) from $SURVEYTABLE where info
= ?');
my $i = 0;
foreach (@numbers) {
my ($nums) = @$_;
$sth->execute( $nums );
++$i;
my $one = $sth->fetchrow_array();
print "one is $one<br>num is $nums<br>\n";
print "<font color=\"#0000FF\"><b>$one</b></font> respondants did not
answer this question" if ($nums eq "0");;
print "<font color=\"#0000FF\"><b>$one</b></font> respondants rated
1<br>" if ($nums eq "1");
print "<font color=\"#0000FF\"><b>$one</b></font> respondants rated
2<br>" if ($nums eq "2");
print "<font color=\"#0000FF\"><b>$one</b></font> respondants rated
3<br>" if ($nums eq "3");
print "<font color=\"#0000FF\"><b>$one</b></font> respondants rated
4<br>" if ($nums eq "4");
print "<font color=\"#0000FF\"><b>$one</b></font> respondants rated
5<br>" if ($nums eq "5");
print "<font color=\"#0000FF\"><b>$one</b></font> respondants rated
6<br>" if ($nums eq "6");
print "<font color=\"#0000FF\"><b>$one</b></font> respondants rated
7<br>" if ($nums eq "7");
print "<font color=\"#0000FF\"><b>$one</b></font> respondants rated
8<br>" if ($nums eq "8");
print "<font color=\"#0000FF\"><b>$one</b></font> respondants rated
9<br>" if ($nums eq "9");
print "<font color=\"#0000FF\"><b>$one</b></font> respondants rated
10<br>" if ($nums eq "10");
}


TIA!

Sylvie.
 
J

James Willmore

On 22 Oct 2003 06:27:00 -0700
my $one = $sth->fetchrow_array();
<snip>

You either need to do:
#place results into _array_ @one - access @one as an array
my @one = $sth->fetchrow_array();
-or-
#place results, as a _reference_, into $one - access $one as a
#reference
my $one = $sth->fetchrow_arrayref();

Right now, you're not getting anything to use in $one. Plus, is there
only _one_ row of data you are interested in? If so, this will work
to get the first row of data returned. If not, you'll need to loop
through the returned values.

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
A fool's brain digests philosophy into folly, science into
<superstition, and art into pedantry. Hence University
<education. -- G. B. Shaw
 
G

Gunnar Hjalmarsson

Sylvie said:
Can someone PLEASE tell me why this is not returning the $one
variable ?

What do you mean by "returning the $one variable"?
I'l pulling results from a survey database table where the answers
was a range from 1 - 10.

I may be stupid, but I still don't understand what it is you are
trying to do. Maybe it would be easier to grasp if you posted the
table structure.
 
G

Glenn Jackman

Sylvie Stone said:
my $sth = $dbh->prepare('select count(*) from $SURVEYTABLE where info
= ?'); [...]
$sth->execute( $nums );
my $one = $sth->fetchrow_array();
print "one is $one<br>num is $nums<br>\n";

What is the result of that print statement?

You want:
my @ary = $sth->fetchrow_array; # this returns an _array_, after all
my $one = $ary[0];
or:
my $aryref = $sth->fetchrow_arrayref;
my $one = $aryref->[0];

You should read the DBI docs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top