Link to home
Start Free TrialLog in
Avatar of jramsden
jramsden

asked on

PHP / ODBC COUNT RECORDS ????

Hi all,

Connecting to a Access Database (Don't ask why), and want to get back a simple SELECT COUNT(*) but it's returning Resource ID #4.

What am I doing wrong.

$query works fine.

Thanks,
Jas.

$odbc = odbc_connect ('leads', '', '') or die( "Could not connect to database at this time. Please try again in 5 minutes." );

$query = odbc_exec($odbc, "SELECT * FROM 0411 ORDER BY Number DESC") or die ( "Error getting data, please try again." );

$total = odbc_exec($odbc, "SELECT COUNT(*) FROM 0411");

echo $total;
Avatar of hernst42
hernst42
Flag of Germany image

You need to fetch the result of that query like this:
$tq = odbc_exec($odbc, "SELECT COUNT(*) FROM 0411");
$total = odbc_fetch_array($tq);
echo "Total is :" . $total[0];
Avatar of jramsden
jramsden

ASKER

Sorry hernst42,

Does not seem to display anything.
I know the data is there as I can diusplay the whole table.

Jas.
What does the following output ??

$odbc = odbc_connect ('leads', '', '') or die( "Could not connect to database at this time. Please try again in 5 minutes." );
$tq = odbc_exec($odbc, "SELECT COUNT(*) FROM 0411");
$total = odbc_fetch_array($tq);

var_dump($total);
I have a access DB that has a unique number, date, time, subject, email and body details.

The page list's all the rows (which it doe's fine) and I need a summary part that show the total rows and that's it.

Your var_dump($total); shows -

array(1) { ["Expr1000"]=> string(3) "595" }

Where 595 is the correct answer.

Jas.
then use $total['Expr1000'] to get that value
Great.

Works fine.

Is it possible to give a grief explaination for var_dump.

Cheers for your expertise.

Jas.
ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks.