So...I pull a recordset from the db. If the recordset is empty, error message; if not, table the results. I want to use
$res_count = odbc_num_rows( $cur );
echo $res_count;
instead of
if (!odbc_fetch_row( $cur )) {
echo \"<center>\n<br>\n<br>\n<h3><i>No records found for this Merchant Number</i></h3>\n<br>\n\";
}
to look for an empty cursor, but
odbc_num_rows( $cur ); keeps coming up -1. However, it works fine on another page that is essentialy the same, but pulls from the db based on a date range instead of a customer ID#. Any help??? Here are chunks from both scripts; if anyone can find the descrepancy, YOU DA (WO)MAN!!!
good script (odbc_num_rows( $cur ) is accurate) :
$cur=odbc_exec($cnx, \"SELECT * FROM MainTB WHERE ReqDate >= \'$Date1\' AND ReqDate <= \'$Date2\' ORDER BY ReqDate\");
if (!odbc_fetch_row( $cur )) {
echo \"<center>\n<br>\n<br>\n<h3><i>No records found in this date range</i></h3>\n<br>\n\";
odbc_close( $cnx);
}
else
{
//////////////////////////////
//print results
/////////////////////////////
$res_count = odbc_num_rows( $cur );
echo $res_count;
echo \"<br><b>\nFound the following records:
blah, blah, blah...
bad script (odbc_num_rows( $cur ) is -1):
<?
$cur=odbc_exec($cnx, \"SELECT * FROM MainTB WHERE MerchantNumber = \'$MerchSearch\'\");
if (!odbc_fetch_row( $cur )) {
include (\"c:\baview\style.inc\");
echo \"<center>\n<br>\n<br>\n<h3><i>No records found for this Merchant Number</i></h3>\n<br>\n\";
$res_count = odbc_num_rows( $cur );
echo $res_count;
odbc_close( $cnx);
}
else
{
//////////////////////////////
//print results
/////////////////////////////
$res_count = odbc_num_rows( $cur );
echo $res_count;
echo \"<center>\n<br>\n<table cols=5 border=1>\n<tr>\n<th>Log Number</th>\n<th>Merchant Name</th>\n\";
echo \"<th>Log Date</th>\n<th>Reason</th>\n<th>Total Amount</th></tr>\n\";
$cur=odbc_exec($cnx, \"SELECT * FROM MainTB WHERE MerchantNumber = \'$MerchSearch\'\");
// fetch the succesive result rows
while( odbc_fetch_row( $cur ) ) {
dump the results into a table, blah blah