Query the database and display the content in arrays by conditions. how can this problem be solved?

Source: Internet
Author: User
Query the database and display the content in arrays by conditions. how can this problem be solved? For website business reasons, the order content contains N different names & nbsp; mobile phone & nbsp; Gender & nbsp; and other information. when uploading a form, I uploaded the order in array mode. now I need to display a total order and sort the order number & nbsp; group each order. Do I have to query the output and display in array mode? Because the database is queried, the content is displayed in arrays by conditions. how can this problem be solved?
Because of the website business, the order content contains N different names, mobile phone gender, and so on. when uploading a form, it is uploaded in an array. now you need to display a total order, do I have to query the output and display of each order by order number? I am a newbie, so I would like to ask you here!

The database structure is as follows:

Id name shouji sex zhuangtai orderid
1 Zhang San 138XXX male 1 1
2 Li Si 186XXX female 1 1
3 Wang Wu 172XXX male 1 1
4 Xiaobao 189XXX male 1 2
5 Shao Zhuang 186XXX male 1 2
6 sweet 133XXX female 2 3
7 Dabao xxx male 3 4
......................

As you can see, all the data is stored in the database according to this structure. each order number only has the same orderid field, and others are different!

Now, you need to output these orders on a page and display them as follows. what should I do? Could you write a method and example? Thank you!

Database array query
------ Solution --------------------
You can write it like this.
$ R = mysql_query ('select orderid, zhuangtai, group_concat ('name') as name, group_concat ('shouji ') as shouji, group_concat ('sex ') as sex from 'order' group by orderid ');
Echo" ";
Echo"NameMobile phoneGender";
While ($ row = mysql_fetch_assoc ($ r )){
$ Shouji_arr = explode (',', $ row ['shouji ']);
$ Sex_arr = explode (',', $ row ['sex']);
Echo" Order Number: ". $ row [orderid]." status: ". $ row ['zhuangtai']."";

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.