<snip href="perldoc DBI">
  ""rows""
       $rv = $sth->rows;

       Returns the number of rows affected by the last row affecting
       command, or -1 if the number of rows is not known or not avail­
       able.

       Generally, you can only rely on a row count after a
       non-"SELECT" "execute" (for some specific operations like
       "UPDATE" and "DELETE"), or after fetching all the rows of a
       "SELECT" statement.

       For "SELECT" statements, it is generally not possible to know
       how many rows will be returned except by fetching them all.
       Some drivers will return the number of rows the application has
       fetched so far, but others may return -1 until all rows have
       been fetched.  So use of the "rows" method or "$DBI::rows" with
       "SELECT" statements is not recommended.

       One alternative method to get a row count for a "SELECT" is to
       execute a "SELECT COUNT(*) FROM ..." SQL statement with the
       same "..." as your query and then fetch the row count from
       that.
</snip>

You may also want to read the perldoc for you DBD module.  Some database
drivers behave differently than the DBI default or may provide
additional informaion (ie. DBD::Informix has an extra hash key
ix_sqlerrd that has an array ref to an array of informix specifc return
values such as the last serial value generated).

On 26 Jun 2001 18:29:55 +0200, Marcus Willemsen wrote:
> Thanks for the advise. I'll give it a try.
> 
> Is there a possiblity to determin the size of the search result, i.e. did 
> the search yield five headlines three or whatever number? And how do I 
> access the elements.
> 
> Grateful for answers
> 
> 
> Marcus
> 
> 
> At 09:51 25.06.2001 -0700, you wrote:
> >You might consider Apache::DBI.  I hear it does what you're interested in 
> >doing,
> >but I haven't done much research on it.  Good luck!
> >
> >Check out search.cpan.org :)
> >
> >C.J.
> >
> >cpan> i Apache::DBI
> >Module id = Apache::DBI
> >     DESCRIPTION  Persistent DBI connection mgmt.
> >     CPAN_USERID  MERGL (Edmund Mergl <[EMAIL PROTECTED]>)
> >     CPAN_VERSION 0.88
> >     CPAN_FILE    M/ME/MERGL/ApacheDBI-0.88.tar.gz
> >     DSLI_STATUS  bmpO (beta,mailing-list,perl,object-oriented)
> >     INST_FILE    (not installed)
> >
> >
> >Marcus Willemsen wrote:
> >
> > > Hi I'm new to Perl and programming in general,
> > >
> > > I wrote (with the help of Learning Perl) the following cgi-scripte to get
> > > headlines out of a database called Message. And it works okay. The next 
> > step
> > > would be to enable a user to click on the headline that interest him and to
> > > display the rest of the message. Can I acess the result of my first search
> > > somehow and pass it on to an new search??
> > >
> > > Best regards
> > >
> > > Marcus
> > >
> > > 1  #!/usr/bin/perl -w
> > > 2
> > > 3  use DBI;
> > > 4  use CGI qw(:standard);
> > > 5  use CGI::Carp(fatalsToBrowser);
> > > 6
> > > 7  print header, start_html("Search"), h1("Search the database");
> > > 8
> > > 9  if (param()) {
> > > 10 $word = param("search");
> > > 11 $datasource = "DBI:mysql:messages;host=localhost;";
> > > 12 $user = "xxx";
> > > 13 $passw = "xxx";
> > > 14 $dbh = DBI->connect($datasource, $user, $passw, {'RaiseError' => 1});
> > > 15 $sth = $dbh->prepare("SELECT Header FROM Message WHERE Header LIKE
> > > '%$word%' GROUP BY Date");
> > > 16 $sth->execute();
> > > 17 while($row = $sth->fetchrow_hashref()) {
> > > 18      print p("$row->{'Header'}\n");
> > > 19 }
> > > 20 print p();
> > > 21 print hr();
> > > 22 print start_form();
> > > 23 print p("New Search", textfield("search"));
> > > 24 print p(submit("Here we go!"), reset("Reset"));
> > > 25 print end_form();
> > > 26 } else {
> > > 27 print hr();
> > > 28 print start_form();
> > > 29 print p("Search for: ", textfield("search"));
> > > 30 print p(submit("Here we go!"), reset("Reset"));
> > > 31 print end_form();
> > > 32 }
> > > 33 print end_html;
> 
> 
--
Today is Boomtime, the 31st day of Confusion in the YOLD 3167
Or not.


Reply via email to