RE: [PHP-DB] Display results of ODBC query
| From: | Andrew Hill | Date: | Fri, 07 Jul 2000 15:15:38 +0000 |
| Subject: | RE: [PHP-DB] Display results of ODBC query | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-946@lists.php.net to get a copy of this message | ||
Todd,
You should be able to use odbc_fetch_row or odbc_fetch_into.
Also try odbc_result, instead of odbc_result_all, since that will return one
result at a time. You will need to do some workarounds to set the row
number, because odbc_num_rows typically _doesn't_ return the number of rows
in a result set.
Here is an odbc_num_rows workaround (not mine, culled from this list a while
back):
<?
$eodb=False;
$counter=0;
$db_connection=odbc_connect("mydsn","user","password",SQL_CUR_DEFAULT);
$result_set=odbc_exec($db_connection,"My SQL Command");
do{
$nextRow;
$nextRow=odbc_fetch_row($result_set);
if(!$nextRow){
$eodb=True;
} else {
// program logic
$counter=++$counter;
}
} while (!$eodb) ;
?>
$counter should return the number of rows you iterated through, and this
also will let you loop through the different records in the found set.
Hope this helps!
Best regards,
Andrew
----------------------------------------------------
Andrew Hill
Professional Services Consultant
OpenLink Software
http://www.openlinksw.com
Universal Database Connectivity Technology Providers
-----Original Message-----
From: Todd Cary [mailto:todd@aristesoftware.com]
Sent: Friday, July 07, 2000 11:00 AM
To: ahill@openlinksw.com
Subject: Re: [PHP-DB] Display results of ODBC query
Andrew -
Thank you for the offer of snippets! I need to try and duplicate some
of the macros that I have in WebHub, the Delphi based Web backend.
Basically it is taking the results of a query and displaying them in a
table format. So, it appears the way one does this is to use our good
old "printf()". But I need to loop through the records and get each one
and then refer to the fields.
If my SQL statement was
SELECT FirstName, LastName, City, State, Zip FROM AddrBk ORDER BY
LastName, FirstName;
I may want to display it as follows:
=========================================================
First Name Last Name City State Zip
=========================================================
Todd Cary Petaluma CA 94952
Ralph Smith Santa Rosa CA 94955
Please do not write the code to do the above; just suggest the functions
to use or give me a snippet.
Todd
--
Todd Cary
Ariste Software
todd@aristesoftware.com