How does thinkphp traverse query results?-php Tutorial

Source: Internet
Author: User
How does thinkphp traverse the query results? I traverse the query results in the controller and then do some processing.
$ SQL = "select CC from XXX ";
$ Db = M ();
$ Rs = $ db-> query ($ SQL); // traverse RS
Foreach ($ rs as $ key => $ value)
{
// Obtain the value of the "CC" field for each record
$ CC = $ value; // failed!
$ CC = $ value [1]; // failed!
$ CC = $ value [0]; // failed!
$ CC = ?? /// // Help !!!!!
}

Foreach ($ rs as $ value)
{
// Obtain the value of the "CC" field for each record
$ CC = $ value; // failed!
$ CC = $ value [1]; // failed!
$ CC = $ value [0]; // failed!
$ CC = ?? /// // Help !!!!!
}


Reply to discussion (solution)

$ Rs = $ db-> query ($ SQL); // traverse RS
Print_r ($ rs );
Post result

Array (33 )(
[0] => array (1 )(
[Column_name] => (string) ID
)
[1] => array (1 )(
[Column_name] => (string) UserName
)
[2] => array (1 )(
[Column_name] => (string) PSW
)
[3] => array (1 )(
[Column_name] => (string) NickName
)

Print does not know where to view the results. move the mouse to display the values of these items.

My statement is to query the names of all columns in a table, and then extract the names and then process them.

Foreach ($ rs as $ value)
{
Echo $ value ['column _ name'];
}

OK. thank you!

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.