Question: Does the mysql record set support the movenext method? function GetTags ($ device)
{
$ SQL = "select tagname from TagList where device = '$ device '";
$ Rs = mysql_query ($ SQL );
While (! $ Rs-> eof) // store the record set to a two-dimensional array
{
$ Tags [] = array ('tagname' => $ rs-> fields ['tagname']-> value );
$ Rs-> MoveNext ();
}
Return $ tags;
Mysql_free_result ($ rs); // Close the dataset
}
Why does the no-object error always occur when I use the movenext method to query mysql databases in php? Does the mysql record set not support this method? how can this problem be implemented? In addition, can the array $ tags in the loop be correctly returned out of the loop?
I want to store the record set to an array and return this array. please take a look!
Reply to discussion (solution)
Yes, not supported
While ($ row = mysql_fetch_assoc ($ rs) // store the record set to a two-dimensional array {$ tags [] = $ row ;}
Return $ tags;
Can this statement return values?
Of course!
What problems have you encountered?
$ Tags has only one record. it is strange that if multiple fields are queried, how can we store them in a two-dimensional array? After the storage result is $ tags ('tagname', 'device', 'unit '), which can be referenced like $ tags [$ I] [tagname? Mysql is not the same as Oracle. please help. thank you!
$ SQL = "select tagname, device, unit from TagList where device = '$ device '";
$ Rs = mysql_query ($ SQL );
.......
Strange, Jing
While ($ row = mysql_fetch_assoc ($ rs) // store the record set to a two-dimensional array {$ tags [] = $ row ;}
After $ tags, isn't it a two-dimensional array?