Rows not being returned ?

Discussion in 'Perl Misc' started by Sylvie Stone, Oct 22, 2003.

  1. Sylvie Stone

    Sylvie Stone Guest

    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.
     
    Sylvie Stone, Oct 22, 2003
    #1
    1. Advertising

  2. On 22 Oct 2003 06:27:00 -0700
    (Sylvie Stone) wrote:
    <snip>
    > 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
     
    James Willmore, Oct 22, 2003
    #2
    1. Advertising

  3. Sylvie Stone wrote:
    > 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.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Oct 22, 2003
    #3
  4. Sylvie Stone <> wrote:
    > 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.

    --
    Glenn Jackman
    NCF Sysadmin
     
    Glenn Jackman, Oct 22, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pikarde
    Replies:
    2
    Views:
    1,054
    Danny Bloodworth
    Nov 24, 2003
  2. Chris Tremblay

    Getting Number Of Rows returned from query

    Chris Tremblay, Sep 9, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    43,074
    http://www.visual-basic-data-mining.net/forum
    Sep 9, 2004
  3. John A Grandy

    2.0 ObjectDataSource number rows returned

    John A Grandy, Mar 16, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    549
    John A Grandy
    Mar 16, 2006
  4. John
    Replies:
    2
    Views:
    2,992
  5. Alec MacLean
    Replies:
    8
    Views:
    630
    Alec MacLean
    Sep 18, 2006
Loading...

Share This Page