Connecting Tech Pros Worldwide Help | Site Map

PHP - Data from access db

  #1  
Old August 23rd, 2007, 10:45 AM
jerryyang_la1@yahoo.com
Guest
 
Posts: n/a
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

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

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

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

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

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page don't load - using odbc and Access db yarivot26 answers 5 October 20th, 2008 04:13 PM
automate mail merge from access (incl php) amfony answers 0 August 13th, 2007 02:06 AM
how can i convert my access db to xml file miladhatam@gmail.com answers 1 March 4th, 2007 12:55 PM
Using PHP to pull from MS Access DB chadlupkes answers 12 March 7th, 2006 03:35 AM
Access DB back-end File bloating jameso321 answers 19 November 13th, 2005 12:24 PM