dstefani has asked for the wisdom of the Perl Monks concerning the following question:
Using DBI however, I can't see a way to get my total returned rows count without doing a seperate COUNT(*) query beforehand and then repeating the same query in a non-grouping fashion. For instance... a chunk of code from a script I'm working on:
I look forward to your input.## chunk 'O' code $sql = "SELECT COUNT(*) "; $sql .= "FROM sc_products "; $sql .= "WHERE name LIKE '%$search_name%' "; $sql .= "AND keywords LIKE '%Color%'"; $sth = $dbh->prepare($sql); $sth->execute || $error->LogError("Error opening database connection f +or product count in search.cgi".$dbh->errstr, 0); # get my count my $count = $sth->fetchrow_array; $sth->finish; $sql = "SELECT name, image2 "; $sql .= "FROM sc_products "; $sql .= "WHERE name LIKE '%$search_name%' "; $sql .= "AND keywords LIKE '%Color%'"; $sth = $dbh->prepare($sql); $sth->execute || $error->LogError("Error opening database connection f +or product count in search.cgi".$dbh->errstr, 0); while(my @results = $sth->fetchrow_array) { ## Use my count in here for some cool table formatting... print "<tr><td class=\"imgs\">... } $sth->finish; $dbh->disconnect();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI, From PHP to Perl
by tantarbobus (Hermit) on Nov 08, 2003 at 19:11 UTC | |
by dstefani (Sexton) on Nov 08, 2003 at 19:29 UTC | |
by pinetree (Scribe) on Nov 09, 2003 at 03:53 UTC | |
|
Re: DBI, From PHP to Perl
by dbwiz (Curate) on Nov 08, 2003 at 19:52 UTC | |
by dstefani (Sexton) on Nov 08, 2003 at 20:41 UTC | |
|
Re: DBI, From PHP to Perl
by mpeppler (Vicar) on Nov 08, 2003 at 19:52 UTC | |
|
Re: DBI, From PHP to Perl
by Arunbear (Prior) on Nov 08, 2003 at 19:34 UTC |