Obtain the field value of the object in the record queried by the Codeigniter database. how can this problem be solved?

Source: Internet
Author: User
Obtain the field value of the object in the record queried by the Codeigniter database. this is a piece of program models layer functioncheckUser () {& nbsp; $ username = $ this-& gt; input-& gt; post ('Username'); & nbsp get the field value of the object in the record queried by the Codeigniter database
This is a piece of code in codeigniter.
Models layer
Function checkUser ()
{
$ Username = $ this-> input-> post ('Username ');
$ Password = $ this-> input-> post ('password ');
$ This-> db-> from ('user ');
$ This-> db-> where ('username', $ username );
$ This-> db-> where ('password', $ password );
$ Query = $ this-> db-> get ();
Return $ query-> result ();
}
Controller layer:

Public function User_Login ()
{
$ This-> load-> model ('user', '', TRUE );
$ Error ['info'] = "incorrect user name or password! ";
$ Data ['query'] = $ this-> User-> checkUser ();
$ Info = $ this-> User-> checkUser ();
// Print the user information obtained here
Print_r ($ info );
If (! Empty ($ data ['query'])
{
$ This-> load-> view ('user/User_Index ');
}
Else
{
$ This-> load-> view ('index', $ error );
}
}

Here is a bit of a tangle of knowledge points!
The printed information is as follows:
Array ([0] => stdClass Object ([id] => 1 [createdate] => 14:32:18 [flag] => 1 [password] => 123 [username] => user1 [email] => ))


How can I obtain the id of the first object in this array ???


------ Solution --------------------
PHP code
// Modelfunction checkUser () {// omit other code // my personal understanding, only one object will be returned here, it is better to directly return a content $ res_data = $ query-> result_array (); // or $ res_data = $ query-> result (); // if (count ($ res_data) = 1) {$ res_data = reset ($ res_data);} return $ res_data ;} // controllerpublic function User_Login () {$ this-> load-> model ('user', '', TRUE ); $ error ['info'] = "incorrect user name or password! "; $ Data ['query'] = $ this-> User-> checkUser (); $ info = $ this-> User-> checkUser (); // Print the user information print_r ($ info) obtained here; // $ info-> id if (! Empty ($ info ['id']) {$ this-> load-> view ('user/User_Index ');} else {$ this-> load-> view ('index', $ error );}}

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.