如何获得成束结果 [英] How to get bunched result
问题描述
我遇到了关于 mysql 表的显示结果的问题.我的 MySql 数据库中有一个这样的表.
I am facing a problem regarding display results from a mysql table. I have a table like this in my MySql Database.
表格名称 - 书籍
+----+--------------------------+--------+-------+-------+----------------+
| id | name | author | price | pages | topic |
+----+--------------------------+--------+-------+-------+----------------+
| 1 | HTML for beginners | Sanju | 200 | 400 | HTML |
| 2 | Master in JavaScript | Sanju | 300 | 500 | JavaScript |
| 3 | Object Oriented PHP | Henry | 200 | 500 | php |
| 4 | Advance AngularJS | Henry | 100 | 400 | AngularJs |
| 5 | Basic Computer Operation | Fred | 200 | 300 | Basic Computer |
| 6 | Rock the world with CSS | Henry | 400 | 500 | Css |
| 7 | Be perfect in browsers | Mark | 250 | 300 | browser |
+----+--------------------------+--------+-------+-------+----------------+
我想显示如下.
+---------------------+---------------+-------+-----------+
| Author Name | Henry | | |
+---------------------+---------------+-------+-----------+
+-------------------------+---------------+-------+-----------+
| Book name | Price | pages | topic |
+-------------------------+---------------+-------+-----------+
| Object Oriented PHP | 200 | 500 | php |
| Advance AngularJS | 100 | 400 | AngularJs |
| Rock the world with CSS | 400 | 500 | Css |
+-------------------------+---------------+-------+-----------+
+---------------------+---------------+-------+-----------+
| Author Name | Sanju | | |
+---------------------+---------------+-------+-----------+
+----------------------+-------+-------+------------+
| Book name | Price | pages | topic |
+----------------------+-------+-------+------------+
| HTML for beginners | 200 | 400 | HTML |
| Master in JavaScript | 300 | 500 | JavaScript |
+----------------------+-------+-------+------------+
+---------------------+---------------+-------+-----------+
| Author Name | Fred | | |
+---------------------+---------------+-------+-----------+
+--------------------------+-------+-------+----------------+
| Book name | Price | pages | topic |
+--------------------------+-------+-------+----------------+
| Basic Computer Operation | 200 | 300 | Basic Computer |
+--------------------------+-------+-------+----------------+
+---------------------+---------------+-------+-----------+
| Author Name | Mark | | |
+---------------------+---------------+-------+-----------+
+------------------------+-------+-------+---------+
| Book name | Price | pages | topic |
+------------------------+-------+-------+---------+
| Be perfect in browsers | 250 | 300 | browser |
+------------------------+-------+-------+---------+
我需要 php 和 mysql 代码.谢谢
I need both php and mysql code. Thanks
推荐答案
似乎您只需要按作者对数据进行排序,但没有将它们按此顺序排列的顺序:
It seems you simply need to order your data by author, however there is no ordering that puts them in this order:
- 亨利
- 三居
- 弗雷德
- 马克
因为这不是按字母顺序升序或降序?
Because this is neither alphabetical ascending or descending?
以下查询将使您能够按作者 ASC/DESC 进行订购:
The following queries will enable you to order by author ASC/DESC:
SELECT * FROM books ORDER BY author ASC;
SELECT * FROM books ORDER BY author DESC;
但是,如果您需要以这种奇怪的顺序输出,您可能需要单独检索每个作者的书籍并一一输出:
However if you need to output in this strange order, you'll likely need to retrieve each author's books individually and output them one by one:
SELECT * FROM books WHERE author = 'Henry';
SELECT * FROM books WHERE author = 'Sanju';
SELECT * FROM books WHERE author = 'Fred';
SELECT * FROM books WHERE author = 'Mark';
然而,我不会发布如何从数据库中检索数据,因为您可以阅读在线教程以获得 PHP/MySQL 代码帮助.请参阅以下链接以获取友好的 PDO 参考:
I wont however be posting how to retrieve the data from the database, for that you can read online tutorials for PHP/MySQL code help. See the below link for a friendly PDO reference:
http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers
希望这会有所帮助 - 抱歉,我无法提供更多帮助.
Hope this helps - sorry I can't be of any more help.
祝你好运!
这篇关于如何获得成束结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!