About the array of mysql_fetch_object ($ SQL)

Source: Internet
Author: User
$ Connmysql_connect (& quot; localhost & quot;, & quot; root & quot;, & quot;) ordie (& quot; database server connection error & quot ;. mysql_error (); & nbsp; mysql_select_db (array problems related to mysql_fetch_object ($ SQL)
$ Conn = mysql_connect ("localhost", "root", "") or die ("database server connection error". mysql_error ());
Mysql_select_db ("xuanke", $ conn) or die ("database access error". mysql_error ());
Mysql_query ("set names gb2312 ");
$ SQL = mysql_query ("SELECT course_id FROM 'info _ selected' WHERE stu_id ");
While ($ r = mysql_fetch_object ($ SQL )){
$ Row [] = $ r;
}
$ Sum = count ($ row );
Echo $ sum;
Echo $ row [0];
Mysql_free_result ($ SQL );
Mysql_close ($ conn );
Under the guidance of experts, is $ row in the above program an array? Why does echo $ sum; show an error while echo $ row [0]; can output the result normally?
If $ row is not an array, how do I output the values in sequence?

------ Solution --------------------
Don't you read the manual?

Mysql_fetch_object returns the object
Most objects can be traversed using foreach
------ Solution --------------------
Discussion

While ($ r = mysql_fetch_object ($ SQL )){
$ Row [] = $ r;
}
I think this sentence should put the returned object in an array! How can I output the values in the array in sequence?

------ Solution --------------------
What do you mean by a display error? Run print_r ($ row) after the loop.

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.