PHP and MS Access Record Count

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thomasp@msala.net

    PHP and MS Access Record Count


    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($co nn,$transid) {
    $sql = "SELECT COUNT(*) FROM tblTransaction WHERE TransID = '$transid'";
    $query = odbc_prepare($c onn,$sql) or die("ERROR");
    odbc_execute($q uery) 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.c om<<<<<<------
    Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
  • Bradley  Holt

    #2
    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:


    Hope this helps.

    --
    Bradley Holt <bradley.holt@g mail.com>


    Comment

    • thomasp@msala.net

      #3
      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($c onn,$sql) or die("ERROR");
      if ($NumRecords=od bc_num_rows($qu ery)<=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.c om<<<<<<------
      Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

      Comment

      • thomasp@msala.net

        #4
        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.c om<<<<<<------
        Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

        Comment

        Working...