http://qs1969.pair.com?node_id=225472


in reply to DBI forgets last record

$sth->fetchrow_array() returns a row (assuming one exists), and has the side effect of moving "past" that row in the set of database results. With this line: print "NO ITEMS IN CART" unless $sth->fetchrow_array();

you try to retrieve a row. There might not be one, in which case you print "no items". But if there is, you don't assign the return value to a variable, so it just gets thrown away -- yet the results pointer still moves forward. That row won't show up in the list you generate in your while loop.

A possible fix could work something like this (untested):

my @fields = $sth->fetchrow_array(); if (!@fields) { print "NO ITEMS IN CART"; } else { while (@fields) { my ($id,$prod_id,$qty) = @fields; print "====== $id ======<br>"; @fields = $sth->fetchrow_array(); } }

        $perlmonks{seattlejohn} = 'John Clyman';