If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > PHP XML data to table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-06-12, 02:15
tempe tempe is offline
Registered User
 
Join Date: Oct 2010
Posts: 27
PHP XML data to table

Hello

First of all, Sorry I'm PHP's noob.
I'm completely new in PHP.

I want to know how to retrieve XML and display the result in table in PHP.

Supposed my XML data are stored in "X" table, "Y" row.
And the XML data structure in "Y" row as follow.
<XML id="">
<A></A>
<B></B>
<C></C>
</XML>

I want to list out data from so that the result will be in table as follow.

A B C
data1 data1 data1
data2 data2 data2

How can I do that in php.
Thanks
Reply With Quote
  #2 (permalink)  
Old 01-07-12, 05:01
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Where do data1 and data2 come from?
What does this have to do with DB2?
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #3 (permalink)  
Old 01-07-12, 08:27
tempe tempe is offline
Registered User
 
Join Date: Oct 2010
Posts: 27
I'm sorry for the lack information.

I'm using DB2 Express-C on debian server and developing PHP application.

The X table has 2 rows. Z and Y rows. The Z row stores id while the Y row stores XML data in native (using DB2 purexml function).

I want to retrieve all the XML data from the Y row and represent it in table.

The XML data structure in "Y" row as follow.
For example.
<XML id="1">
<A>data1</A>
<B>data2</B>
<C>data3</C>
</XML>

<XML id="2">
<A>data4</A>
<B>data5</B>
<C>data6</C>
</XML>

.
.
.

<XML id="n">
<A>datax</A>
<B>datay</B>
<C>dataz</C>
</XML>



I want to list out data so that the result will be in table as follow.

A B C
data1 data2 data3
data4 data5 data6
.
.
.
datax datay dataz

How can I do that in php.
Thanks
Reply With Quote
  #4 (permalink)  
Old 01-07-12, 17:13
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Not 100% sure if I understood your database design correctly, but it could be something in the following style:
Code:
<html><body><table><th><td>A</td><td>B</td><td>C</td></th>
<?php
 $database = 'SAMPLE'; $user = 'db2inst1'; $password = 'ibmdb2';
 $conn = db2_connect($database, $user, $password);
 $sql =
 'SELECT  XMLQUERY(\'$Y/A\' PASSING Y) AS a,
          XMLQUERY(\'$Y/B\' PASSING Y) AS b,
          XMLQUERY(\'$Y/C\' PASSING Y) AS c
  FROM x';
$stmt = db2_prepare($conn, $sql);
$result = db2_execute($stmt);
while ($row = db2_fetch_array($stmt)) {
    print "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td></tr>";
} ?>
</table></body></html>
For the DB2 bindings in PHP, and how to install, see PHP: IBM DB2 Functions - Manual
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/

Last edited by Peter.Vanroose; 01-07-12 at 17:16.
Reply With Quote
  #5 (permalink)  
Old 01-09-12, 19:27
tempe tempe is offline
Registered User
 
Join Date: Oct 2010
Posts: 27
Thanks for the reply.

However I got this errors.
Warning: db2_execute(): Statement Execute Failed in XXX.php on line 17 Warning: db2_fetch_array(): Column information cannot be retrieved in XXX.php on line 18

The errors occurred on
(line 17) $result = db2_execute($stmt);
(line 18) while ($row = db2_fetch_array($stmt)) {

I guess there is something wrong on sql statement.
Reply With Quote
  #6 (permalink)  
Old 01-10-12, 06:33
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by tempe View Post
I guess there is something wrong on sql statement.
In that case, first try the SQL statement (literally, as it would be passed by PHP) in a "normal" DB2 interface, and modify it until it works. There could, e.g., be a problem with the table or column name(s). In my example the table is called "X" and the column is called "Y"; you'll possibly have to replace those.
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On