[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP / ODBC COUNT RECORDS ????

Posted on 2004-11-03
10
Medium Priority
?
2,545 Views
Last Modified: 2013-12-13
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;
0
Comment
Question by:jramsden
  • 4
  • 4
8 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 12481888
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
 

Author Comment

by:jramsden
ID: 12481957
Sorry hernst42,

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

Jas.
0
 
LVL 48

Expert Comment

by:hernst42
ID: 12482012
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jramsden
ID: 12482063
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
 
LVL 48

Expert Comment

by:hernst42
ID: 12482227
then use $total['Expr1000'] to get that value
0
 

Author Comment

by:jramsden
ID: 12482451
Great.

Works fine.

Is it possible to give a grief explaination for var_dump.

Cheers for your expertise.

Jas.
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 12483049
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
 

Author Comment

by:jramsden
ID: 12483113
Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question