PHP - Data from access db

PHP - Data from access db

am 23.08.2007 11:36:04 von jerryyang_la1

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


$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

Re: PHP - Data from access db

am 23.08.2007 12:35:30 von usenet

In article <1187861764.001109.64820@l22g2000prc.googlegroups.com>,
wrote:
> 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

Re: PHP - Data from access db

am 23.08.2007 12:42:15 von jerryyang_la1

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

Re: PHP - Data from access db

am 23.08.2007 15:16:51 von Jerry Stuckle

jerryyang_la1@yahoo.com wrote:
> I'm using the code below as a base for a connect to an access
> database.
> This works well, but I have an issue...
>
>
> > $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
==================

Re: PHP - Data from access db

am 24.08.2007 00:31:16 von usenet

In article <1187865735.390129.84170@q3g2000prf.googlegroups.com>,
wrote:
> yes that's what I would like to do.

Errr, good. What is what you'd like to do?


> 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