$ 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.