How can I write such an SQL statement?

Source: Internet
Author: User
How can I write such an SQL statement? php mysql

I wrote it like this. I want to use php to output an xml file. below is what I wrote. it is not easy to write. it is a newbie:
Create table 'Tables '(
'Tid' int (10) not null auto_increment,
'Parentid' int (10) DEFAULT '0' not null,
'Levelid' int (10) DEFAULT '0' not null,
'Imgname' varchar (255) not null default '',
'Imgtitle' varchar (255) not null default '',
'URL' varchar (255) not null default '',

Primary key ('tid ')
) ENGINE = MyISAM default charset = utf8 AUTO_INCREMENT = 1;
The output format is as follows:











How can I write my php? I cannot classify and generate xml after writing it. php is written like this. please give me some advice. thank you.
Include ('Conn. php ');
$ Result = mysql_query ("SELECT * FROM tables ");
While ($ row = mysql_fetch_array ($ result ))
{
If (! $ Row ['parentid'] | $ row ['parentid'] = 2 ){
If ($ row ['levelid'] = 2 | $ row ['parentid'] = 2 ){
// Echo $ row ['parentid']. "". $ row ['levelid']. "". $ row ['imgname']. "". $ row ['imgtitle']. "". $ row ['URL']. "". $ I;
// Echo"
";
//
}
}
}


Reply to discussion (solution)

Let's talk about it first.




Corresponding to which fields in the table

Insert into tables VALUES ('1', '0', '1', 'c _ 1', 'Button ', 'null ');
Insert into tables VALUES ('2', '1', '1', 'tag1', 'tag1 ');
Insert into tables VALUES ('3', '1', '2', 'Button 2', 'Button 2'', '2.jpg ');

In fact, I want to extract data from the database to generate an xml file. the xml format is like this.











I don't know how to write a table to facilitate php reading. I am afraid that reading will become slow when there is more data. thank you for your advice. thank you!

Are you sure you don't have any help?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.