Connecting Tech Pros Worldwide Help | Site Map

PHP and MS Access Record Count

thomasp@msala.net
Guest
 
Posts: n/a
#1: Sep 11 '05

I am trying to get a record count of a PHP query on a MS Acess database
using ODBC with a DSN for MS ACCESS connection. I got this code from the
PHP manual user notes. It seems to return the correct recount if the count
is greater than 0. It the count is 0 it returns the value of the $transid
variable in the code. Can someone tell me what I am doing wrong? I need
something that returns 0 if not records are found and an accurate count if
records are found. This seems like overkill to get a simple record count.
Thanks,
Thomas

function recordcount($conn,$transid) {
$sql = "SELECT COUNT(*) FROM tblTransaction WHERE TransID = '$transid'";
$query = odbc_prepare($conn,$sql) or die("ERROR");
odbc_execute($query) or die("ERROR");
$rc = odbc_fetch_into($query, $mycount);
$count = $mycount[0];
return $count;
}

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Bradley Holt
Guest
 
Posts: n/a
#2: Sep 11 '05

re: PHP and MS Access Record Count


I'm not sure if this will help, but you may want to check the number of
rows first before you try reading the count:
http://www.php.net/manual/en/function.odbc-num-rows.php

Hope this helps.

--
Bradley Holt <bradley.holt@gmail.com>
http://www.gtalkprofile.com/profile/2.html

thomasp@msala.net
Guest
 
Posts: n/a
#3: Sep 11 '05

re: PHP and MS Access Record Count



This returns the value of the $transid variable everytime.

$sql = "SELECT COUNT(*) FROM tblTransaction WHERE TransID = '$transid'";
$query = odbc_prepare($conn,$sql) or die("ERROR");
if ($NumRecords=odbc_num_rows($query)<=0) {
$NumRecords = 0;
odbc_fetch_row($query,0);
while (odbc_fetch_row($query))
{
$NumRecords++;
}
odbc_fetch_row($query, 1);
}
return $NumRecords;

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
thomasp@msala.net
Guest
 
Posts: n/a
#4: Sep 11 '05

re: PHP and MS Access Record Count



I was reading the wrong value. The code in the original post works just
fine.

Sorry,

Thomas

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Closed Thread