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;
jramsdenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hernst42Commented:
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];
0
jramsdenAuthor Commented:
Sorry hernst42,

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

Jas.
0
hernst42Commented:
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);
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

jramsdenAuthor Commented:
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.
0
hernst42Commented:
then use $total['Expr1000'] to get that value
0
jramsdenAuthor Commented:
Great.

Works fine.

Is it possible to give a grief explaination for var_dump.

Cheers for your expertise.

Jas.
0
hernst42Commented:
var_dump is only for debugging. It prints php-structures more readable by a user. So I can guess which name access had given for count(*)

you might try
$tq = odbc_exec($odbc, "SELECT COUNT(*) as num FROM 0411");
...

and then access the value via $total['num'] instead of the given name Expr1000 of Access.

http://de3.php.net/var_dump
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jramsdenAuthor Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.