Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with displaying columns/fields of a table, please

Status
Not open for further replies.

kknorpp001

Technical User
Dec 22, 2003
13
US
Hello.

I am attempting to display the contents of a table and, naturally, would like to include the column/field NAMES at the top of the output. The following code with print out the 1st column name, so I am getting close, and have tried several ways to get it to print the remaining columns, but no luck. Help, please. Many thanks in advance....


$columns = odbc_columns ($connection, "PC.mdb", "", "results");

$item = odbc_result($columns, 4);

print "$item";
 
Why not try the odbc_fetch_into() function.

Keep your first line as is but then do:

$rowcount = odbc_fetch_into($columns, $namearray);
if ($rowcount != FALSE)
{
foreach ($rowcount as $elem)
print $elem;
}
else
print "Could not fetch rows...";

Hope this helps

Devon
 
Thanks. That allows me to see the array, which is posted below. But, instead of returning the column names, it is returning the details of the first column only. How do I get the other columns? Thanks again for your help..

D:\HTML\USERS\DOMAINCOM\database\PC

results
RiderNum
4
INTEGER
10
4
0
10
1


4


1
YES
1
 
It seems as though ODBC_fetch_into only grabs the array for one column. Try putting the ODBC_fetch_into statement into a while loop. This way it will keep fetching until there are no more columns to fetch. If you're only interested in the column name, put the column names into their own array:

while (ODBC_fetch_into($columns, $rowarray)
array_push($colarray, $rowarray[COLUMN_NAME]);

foreach ($colarray as $var)
print &quot;$var <BR>&quot;;

Cheers,
Devon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top