473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Create XML with MySQL and PHP

34
Hi there dose anyone know weather php can output XML
Zar
Jul 29 '07 #1
10 1788
kovik
1,044 Expert 1GB
Yes, yes it can. XML is just like HTML, but with different markup. Any more questions?
Jul 29 '07 #2
Zarwadi
34
Hi thanks I've create xml using MySQL and php, but i need to select paticular rows from my data base I'v try using WHERE in my query but this is not working can you help here is my code:
//
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. header("Content-type:text/xml");
  3. $con=mysql_connect("localhost","userrname","password")or die(mysql_error());
  4. mysql_select_db("database",$con);
  5. $query ="SELECT*FROM male WHERE Imagename ='$glog ORDER BY imagename ASC";
  6. $resultID=mysql_query($query, $con) or die("Data not found.");
  7. $xml_output="<?xml version=\"1.0\"?>\n";
  8. $xml_output.="<products title='Product'>\n";
  9. for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
  10. $row = mysql_fetch_assoc($resultID);
  11. $xml_output .= "\t<InSert itemdiscription='$row[name]'>\n";
  12. $xml_output .= "\t<id ident='$row[iddent]'></id>\n";
  13. $xml_output .= "\t<Size gs='$row[size]'></Size>\n";
  14. $xml_output .= "\t<Price gp='$row[price]'></Price>\n";
  15. $xml_output .= "\t<Quantity gq='$row[quantity]'></Quantity>\n";
  16. $xml_output .= "\t<Discription gd='$row[discription]'></Discription>\n";
  17. $xml_output .= "\t<Imagename gi='$row[imagename]'></Imagename>\n";
  18. $xml_output .= "\t</InSert>\n";
  19. }
  20. $xml_output .= "</products>";
  21. echo $xml_output; 
  22. ?>
kind regard Zar
Jul 31 '07 #3
ak1dnar
1,584 Expert 1GB
what should be the structure for your xml file? show it to us.
it is not clear enough for me in your coding.

if it is me,I'll create my XML elements like this.

Expand|Select|Wrap|Line Numbers
  1. $xml_output .= '<itemdiscription>'.$row['name'].'</itemdiscription>';
  2. // and Others here..
  3.  
Jul 31 '07 #4
Zarwadi
34
The code is for a flash site which has already been made so i have to reflect who the old XML code was whiten: here is the display. Hope you can help
Zar

<products title="Product">
<InSert itemdiscription="Raincoat">
<id ident="c600"/>
<Size gs="32"/>
<Price gp="47.00"/>
<Quantity gq="1"/>
<Discription gd="1960s Italian wool gabardine raincoat Lobster boy. Condition Ex"/>
<Imagename gi="children/childimages/April07001.jpg"/>
</InSert>
<InSert itemdiscription="Velvet waistcoat">
<id ident="00282"/>
<Size gs="27"/>
<Price gp="18.00"/>
<Quantity gq="1"/>
<Discription gd="1980s Velvet waistcoat. Condition Ex"/>
<Imagename gi="children/childimages/DSC00028.jpg"/>
</InSert>
<InSert itemdiscription="Poloneck jumper">
<id ident="00281"/>
<Size gs="26"/>
<Price gp="18.00"/>
<Quantity gq="1"/>
<Discription gd="1970s Poloneck jumper. Condition Ex"/>
<Imagename gi="children/childimages/DSC00028.jpg"/>
</InSert>
<InSert itemdiscription="Wool shawl">
<id ident="00283"/>
<Size gs="None"/>
<Price gp="9.00"/>
<Quantity gq="1"/>
<Discription gd="1960s Hand embroidered tyrol wool shawl. Condition Ex"/>
<Imagename gi="children/childimages/DSC00028.jpg"/>
</InSert>
</products>
Jul 31 '07 #5
ak1dnar
1,584 Expert 1GB
This will match with your out put.do the changes against to your database table.
I just removed some unwanted contents inside your while loop.

post back if there is doubt.

Thanks ! -ajaxrand


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. header("Content-type:text/xml");
  3. $con=mysql_connect("localhost","root","dba")or die(mysql_error());
  4. mysql_select_db("test",$con);
  5. $query ="SELECT * FROM products";
  6. $resultID=mysql_query($query, $con) or die("Data not found.");
  7. $xml_output="<?xml version=\"1.0\"?>\n";
  8. $xml_output.="<products>";
  9. for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
  10. $row = mysql_fetch_assoc($resultID);
  11. $xml_output .= '<InSert itemdiscription="'.$row['p_id'].'">';// ELEMENT STARTS
  12. $xml_output .= '<id ident="'.$row['p_name'].'"></id>'; // CHILDS 
  13. // REPEAT THE OTHER CHILDS HERE
  14.  
  15. $xml_output .= '</InSert>'; // ELEMENT END
  16. }
  17. $xml_output .= "</products>";
  18. echo $xml_output; 
  19. ?>
  20.  
Aug 1 '07 #6
ak1dnar
1,584 Expert 1GB
Did you Know?
How to use CODE tags arround your codings.

Answer is here
Aug 1 '07 #7
gregerly
192 Expert 100+
Hi thanks I've create xml using MySQL and php, but i need to select paticular rows from my data base I'v try using WHERE in my query but this is not working can you help here is my code:
//
Expand|Select|Wrap|Line Numbers
  1. $query ="SELECT*FROM male WHERE Imagename ='$glog ORDER BY imagename ASC";
  2.  
I might try spacing things out in your query, don't know if this is exactly how you have it written in your code, but it seems cramped to me. You also have a single quote left out after the $glog variable. I would rewrite like this:

[PHP]$query = "SELECT * FROM male WHERE Imagename = '$glog' ORDER BY imagename ASC;"[/PHP]

Also, does the "male" table have two fields named imagename, one lower case and one upper case as you have it written in your query. If so you (I don't even thing you can do that in mysql), you may want to think about your table structures again. Also, your ordering by the same field specified in the Where clause, which means they are all going to be the same, thus you can't reorder them. Seems pointless to me....

But i've been wrong before!

Greg
Aug 1 '07 #8
ak1dnar
1,584 Expert 1GB
I might try spacing things out in your query, don't know if this is exactly how you have it written in your code, but it seems cramped to me. You also have a single quote left out after the $glog variable. I would rewrite like this:

[PHP]$query = "SELECT * FROM male WHERE Imagename = '$glog' ORDER BY imagename ASC;"[/PHP]
Greg,
you are absolutely correct. I think I also missed the single quote in the original post.

but, to the best of my knowledge this kind of MYSQL queries are executing perfectly.

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT*FROM products
  3.  
Aug 1 '07 #9
Zarwadi
34
Greg,
you are absolutely correct. I think I also missed the single quote in the original post.

but, to the best of my knowledge this kind of MYSQL queries are executing perfectly.

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT*FROM products
  3.  
HI thanks for your help, but I rewrote the flash file out and solved the problem
thanks for all your help
Zar
Aug 1 '07 #10
ak1dnar
1,584 Expert 1GB
HI thanks for your help, but I rewrote the flash file out and solved the problem
thanks for all your help
Zar
Glad to hear that,you got it working.Post back anytime if you have any doubts.!
-Ajaxand
Aug 1 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: dev | last post by:
how create a temp table as a copy of a existing table and then update1 field and insert the hole temp table back in the existing table? please any help? if i have 10 fields in 1 record and...
0
by: Morten Gulbrandsen | last post by:
USE company; DROP TABLE IF EXISTS EMPLOYEE; CREATE TABLE EMPLOYEE ( # PK SSN CHAR(9) NOT NULL, # FK SUPERSSN CHAR(9), DNO INT NOT NULL DEFAULT 1, CONSTRAINT EMPPK
4
by: Mmm_moo_cows | last post by:
Hi, I'm new to the world of mysql and i'm having alot of trouble with it. All i want to do is create a page with a response form, e.g. name etc and some radio buttons (part of a uni project,...
0
by: Marc | last post by:
Hello, I have a problem with mySql server: I can only run it as root. I use mySql 4.0.15 and phpMyAdmin 2.5.5. on Mac OSX 10.3.2. I run mySql server as root, log in via phpMyAdmin as root and...
0
by: niku | last post by:
Hello all. I'm trying to get mysql installed on OpenBSD 3.4. Unfortunately, it appeares that the port only installes the mysql-client, and one needs to install the -server package seperately. This...
2
by: Alicia | last post by:
Does anyone know why I am getting a "Syntax error in Create Table statement". I am using Microsoft Access SQL View to enter it. Any other problems I may run into? CREATE TABLE weeks (...
2
by: Galina | last post by:
Hello I need to get data from 4 Oracle tables and combine them into a temporary table in my application. I get data using a pass-through query dynamically created in code: mySQL = "SELECT...
1
by: Henry16 | last post by:
Hi. Impossible to create a database using MySQL !!! Message : #1006 - Can't create database 'boby'. (errno: 13) I was told : chown mysql.mysql -R /var/lib/mysql chmod 750 -R /var/lib/mysql...
14
by: mistral | last post by:
Need php script to create mySQL database programmatically; since hosting configuration may not allow create database from script, script also need eliminate/rewrite all restrictions in appropriate...
2
by: Hetal | last post by:
Hi... I am a newbie VB.NET developer and i am looking at working with ADO.NET rather than ADO. In one of our native VB application with ADO, we used to create 1 connection object and that would...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.