How to display the data queried by mysql

Source: Internet
Author: User
How to display data queried by mysql $ SQL = & quot; SELECTc. cat_name, a. titleFROMhc_articleasaLEFTJOINhc_article_catAScONa.cat_id = c. cat_id & q the data display method queried by mysql

$ SQL = "SELECT c. cat_name, a. title FROM hc_article as a LEFT JOIN hc_article_cat AS c ON a. cat_id = c. cat_id ";
Use the preceding statement to query

Array
(
[0] => Array
(
[Cat_name] => Beginner's Guide
[Title] => user registration
)

[1] => Array
(
[Cat_name] => Beginner's Guide
[Title] => shopping guide
)
)



How can I arrange them


Array
(
[0] => Array
(
[Cat_name] => Array ([0] => Beginner's Guide)
[Title] => Array ([0] => user registration [1] => Shopping Guide)

)

)

------ Solution --------------------
PHP code
$ Ar = Array ('0' => Array ('cat _ name' => 'beginner's Guide', 'title' => 'User registration '), '1' => Array ('cat _ name' => 'newbie's guide ', 'title' => 'shopping Guide'); foreach ($ ar as $ v) {if (! $ T [$ v ['cat _ name']) {$ t [$ v ['cat _ name'] ['cat _ name'] = array ($ v ['cat _ name']); $ t [$ v ['cat _ name'] ['title'] = array ($ v ['title']);} else $ t [$ v ['cat _ name'] ['title'] [] = $ v ['title'];} print_r (array_values ($ t ));

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.