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?