LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-06-2015, 09:08 AM   #1
takener
LQ Newbie
 
Registered: Jul 2015
Posts: 4

Rep: Reputation: Disabled
mysql to xml


I'm having some troubles to export my data from my DB, im using phpmyadmin and i want to export alot of data but i wanted in dat way

<stuff>
<id>111</id>
<country>USA</country>
<photos>
<photo>http:www.photo1.com</photo>
<photo>http:www.photo2.com</photo>
<photo>http:www.photo3.com</photo>
</photos>

<id>222</id>
<country>USA</country>
<photos>
<photo>http:www.photo12.com</photo>
<photo>http:www.photo22.com</photo>
<photo>http:www.photo32.com</photo>
<photo>http:www.photo42.com</photo>
<photo>http:www.photo52.com</photo>
</photos>
...
</stuff>

i have a db with 7 tables all related to one with the id and i dont know if i have to create a sigle table without realations (i dont think thats a good idea because i dont know how i can put all the photos in one field)

i tried to export the data with the export option of myphpadmin but i cant select how i want the data to be exported like and its exported only table by table

<stuff>

<table name="identification">

<column name="id">111</column>
<column name="contry">USA</column>
</table>

<table name="identification">

<column name="id">222</column>
<column name="contry">USA</column>
</table>

<table name="photos">

<column name="photo">http:www.photo1.com</column>
<column name="photo">http:www.photo2.com</column>
<column name="photo">http:www.photo3.com</column>
</table>


<table name="photos">

<column name="photo">>http:www.photo12.com</column>
<column name="photo">http:www.photo22.com</column>
<column name="photo">http:www.photo32.com</column>
<column name="photo">http:www.photo42.com</column>
<column name="photo">http:www.photo52.com</column>

</table>
</stuff>


PD: sorry about my writting but english is not my native language
 
Old 07-07-2015, 01:50 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
Maybe you can create a view of the data with WHERE clause, GROUP BY, ORDER BY and then export the view with phpMyAdmin? This way you have some access to the structure the xml will have.

cheers, j
 
Old 07-07-2015, 02:58 AM   #3
takener
LQ Newbie
 
Registered: Jul 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by j-ray View Post
Maybe you can create a view of the data with WHERE clause, GROUP BY, ORDER BY and then export the view with phpMyAdmin? This way you have some access to the structure the xml will have.

cheers, j
tx a lot but i allready tried that but the problem is that i need all the photos together and in that way i get a lot of rows like these

<stuff>
<table name="identification">
<column name="id">111</column>
<column name="contry">USA</column>
<photo>http:www.photo1.com</photo>
</table>

<table name="identification">
<id>111</id>
<country>USA</country>
<photo>http:www.photo2.com</photo>
</table>

<table name="identification">
<column name="id">111</column>
<column name="contry">USA</column>
<photo>http:www.photo3.com</photo>
</table>

<table name="identification">
<column name="id">111</column>
<column name="contry">USA</column>
<photo>http:www.photo12.com</photo>
</table>
...
</stuff>


and when i make the group by i only get one photo and i loose the other ones

Last edited by takener; 07-07-2015 at 03:02 AM.
 
Old 07-07-2015, 04:14 AM   #4
takener
LQ Newbie
 
Registered: Jul 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
solved:
the solution i made was with a script in php like these
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "admin";
$dbname = "test";
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);


$sql = "SELECT * FROM books";
$q = mysql_query($sql) or die(mysql_error());
$xml = "<library>";
while($r = mysql_fetch_array($q)){
$xml .= "<book>";
$xml .= "<id>".$r['id']."</id>";
$xml .= "<title>".$r['title']."</title>";
$xml .= "<author>".$r['author']."</author>";
$xml .= "<description>".$r['description']."</description>";
$xml .= "<on_sale>".$r['on_sale']."</on_sale>";
$xml .= "</book>";
}
$xml .= "</library>";
$sxe = new SimpleXMLElement($xml);
$sxe->asXML("test.xml");

?>

from: http://www.phpeveryday.com/articles/...base-P534.html
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL to XML including data, DTD and XML Schema rm_-rf_windows Linux - General 3 07-06-2015 07:43 AM
xml and mysql kushalkoolwal Linux - Software 3 07-02-2009 08:21 AM
XML <->MySql in Perl?? rsz Programming 0 10-06-2004 09:40 AM
html, xml, php, mysql atheist Programming 8 06-07-2004 01:28 PM
C++ question: MySQL or XML? BlackT Programming 7 07-21-2003 07:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration