Gossamer Forum
Home : General : Perl Programming :

SQL Count

Quote Reply
SQL Count
Why does this code..
Code:

#if (!defined ("$start_pos"))
#{
$start_pos = 0;
$page_size = 5; # number of results per page

$query_numrows = "SELECT COUNT(*) FROM geog";
$max_rec = $sth = $dbh->prepare($query_numrows);
$sth->execute();
$sth->finish;

if ($max_rec == 0)
{
&error_html("Sorry, no records were found");
exit;
}
$page_size = $page_size;
$max_rec = $max_rec;
#}


Return this...

DBI::st=HASH(0x81e8e00


?


- wil
Quote Reply
Re: [Wil] SQL Count In reply to
Hi,

Yes, as you have:

$max_rec = $sth = $dbh->prepare($query_numrows);

so max_rec is a sth handle. I don't think you want this. I think you want:

($max_rec) = $sth->fetchrow_array;

to put into $max_rec the result of your sql query.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] SQL Count In reply to
Hi Alex

Yes. I got round it by changing it to:

$max_rec = $dbh->selectrow_array ("SELECT COUNT(*) FROM geog");

I belive this a better way of retrieving max number of rows anyway.

Thanks

- wil