Question: Does mysql record set support the movenext method?

Source: Internet
Author: User
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?

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.