By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,689 Members | 1,731 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,689 IT Pros & Developers. It's quick & easy.

PHP and MS Access Record Count

P: n/a

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
Sep 11 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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 <br**********@gmail.com>
http://www.gtalkprofile.com/profile/2.html

Sep 11 '05 #2

P: n/a

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
Sep 11 '05 #3

P: n/a

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
Sep 11 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.