Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 23rd, 2007, 10:45 AM
jerryyang_la1@yahoo.com
Guest
 
Posts: n/a
Default PHP - Data from access db

I'm using the code below as a base for a connect to an access
database.
This works well, but I have an issue...


<?php
$db = "./access.mdb" ;
$pass = "1234" ;

$conn = new COM("ADODB.Connection") ;
$sql = "DRIVER={Microsoft Access Driver (*.mdb)} ;
DBQ=". realpath($db) ." ;
uid=admin ;
pwd=$pass ;" ;
$conn->open($sql);
$rs = $conn->execute("SELECT * FROM TableName");
while (!$rs->EOF) {
echo $rs->Fields['FieldID']->Value ;
echo $rs->Fields['FieldName']->Value ;
$rs->MoveNext() ;
}
$rs->Close() ;
$conn->Close() ;
?>



using this:
while (!$rs->EOF) {
echo $rs->Fields['FieldID']->Value ;
echo $rs->Fields['FieldName']->Value ;
$rs->MoveNext() ;
}

The data is data is extracted and displayed on the screen.

as:

ID: 123456

Field1: value1

Field2: value12

ID: 123456

Field1: value2

Field2: value22

ID: 123456

Field1: value3

Field2: value23

ID: 123456

Field1: value4

Field2: value24





But I need to do this!!


Show this ONCE : echo $rs->Fields['FieldID']->Value ;

Loop on this : echo $rs->Fields['Field1']->Value ;

Loop on this : echo $rs->Fields['Field2']->Value ;

The end result being


ID: 123456

Field1: value1, value2, value3, value4

Field2: value12, value22, value23, value24


HELP :)

Any ideas ??

Thanks

  #2  
Old August 23rd, 2007, 11:35 AM
Usenet
Guest
 
Posts: n/a
Default Re: PHP - Data from access db

In article <1187861764.001109.64820@l22g2000prc.googlegroups. com>,
wrote:
Quote:
HELP :)
What you want is not clear from what you've said .
However, at a guess if what you want is more along the lines of

ID xyz

Field Names FN1, FN2, FN3
Field Values FV1, FV2, FV3

Then :-

1) you look like you've got a very odd table structure.

2) Save the values into text strings and then output those

3) you probably ought to learn more about databases, and use one,
not Access.


Mark

  #3  
Old August 23rd, 2007, 11:45 AM
jerryyang_la1@yahoo.com
Guest
 
Posts: n/a
Default Re: PHP - Data from access db

Hi

yes that's what I would like to do.

I'm stuck the MDB as is... I've been asked to try and work with it !!

Any ideas how to get this to work ?

Thanks

  #4  
Old August 23rd, 2007, 02:25 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: PHP - Data from access db

jerryyang_la1@yahoo.com wrote:
Quote:
I'm using the code below as a base for a connect to an access
database.
This works well, but I have an issue...
>
>
<?php
$db = "./access.mdb" ;
$pass = "1234" ;
>
$conn = new COM("ADODB.Connection") ;
$sql = "DRIVER={Microsoft Access Driver (*.mdb)} ;
DBQ=". realpath($db) ." ;
uid=admin ;
pwd=$pass ;" ;
$conn->open($sql);
$rs = $conn->execute("SELECT * FROM TableName");
while (!$rs->EOF) {
echo $rs->Fields['FieldID']->Value ;
echo $rs->Fields['FieldName']->Value ;
$rs->MoveNext() ;
}
$rs->Close() ;
$conn->Close() ;
?>
>
>
>
using this:
while (!$rs->EOF) {
echo $rs->Fields['FieldID']->Value ;
echo $rs->Fields['FieldName']->Value ;
$rs->MoveNext() ;
}
>
The data is data is extracted and displayed on the screen.
>
as:
>
ID: 123456
>
Field1: value1
>
Field2: value12
>
ID: 123456
>
Field1: value2
>
Field2: value22
>
ID: 123456
>
Field1: value3
>
Field2: value23
>
ID: 123456
>
Field1: value4
>
Field2: value24
>
>
>
>
>
But I need to do this!!
>
>
Show this ONCE : echo $rs->Fields['FieldID']->Value ;
>
Loop on this : echo $rs->Fields['Field1']->Value ;
>
Loop on this : echo $rs->Fields['Field2']->Value ;
>
The end result being
>
>
ID: 123456
>
Field1: value1, value2, value3, value4
>
Field2: value12, value22, value23, value24
>
>
HELP :)
>
Any ideas ??
>
Thanks
>
I guess the first thing I would do is use the ODBC driver instead of the
COM object. I've never used the COM object.

But what is the structure of your database, and the data in it?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  #5  
Old August 23rd, 2007, 11:35 PM
Usenet
Guest
 
Posts: n/a
Default Re: PHP - Data from access db

In article <1187865735.390129.84170@q3g2000prf.googlegroups.c om>,
wrote:
Quote:
yes that's what I would like to do.
Errr, good. What is what you'd like to do?

Quote:
Any ideas how to get this to work ?
Yes, I gave you one, but as I and Jerry have said, without a better
idea of what you want to do and how it relates to your table structure
it's a bit hard to guess

Mark

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles