|
Posted by Jerry Stuckle on 08/23/07 13:16
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...
>
>
> <?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
==================
Navigation:
[Reply to this message]
|