note 11278 modified in function.odbc-num-rows by felipe

From: Date: Tue, 22 Jul 2008 18:51:22 +0000
Subject: note 11278 modified in function.odbc-num-rows by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142523@lists.php.net to get a copy of this message
A better method for calculating the record count (without being forced to use objects) is: <?php function RecordCount($sql_id, $CurrRow = 0) { $NumRecords = 0; odbc_fetch_row($sql_id, 0); while (odbc_fetch_row($sql_id)) { $NumRecords++; } odbc_fetch_row($sql_id, $CurrRow); return $NumRecords; } ?> The only problem arises (in both this and the bit of code relying on objects) is when the driver does not support fetching a specific row number. In that case, the query will have to be run again (and cross your fingers that the data has not changed in the datasource). --was-- A better method for calculating the record count (without being forced to use objects) is: function RecordCount($sql_id, $CurrRow = 0) { $NumRecords = 0; odbc_fetch_row($sql_id, 0); while (odbc_fetch_row($sql_id)) { $NumRecords++; } odbc_fetch_row($sql_id, $CurrRow); return $NumRecords; } The only problem arises (in both this and the bit of code relying on objects) is when the driver does not support fetching a specific row number. In that case, the query will have to be run again (and cross your fingers that the data has not changed in the datasource). http://php.net/manual/en/function.odbc-num-rows.php

« previous php.notes (#142523) next »