In the following code, how do I remove the reference parameter and use the return value instead?

Source: Internet
Author: User
The code is as follows: {code...} gongchengleibie is a database table with a three-layer tree structure. if you want to remove the reference parameter $ str, use the return value method and try again. How can I change it? If it cannot be changed, why? Thank you for your attention or answers. Such...

The code is as follows:

// Return the specified $ aid Project Category id and its subordinate category id. // parameter: // $ aid project category, int type // $ conn database connection // $ str, return value, string type // return: string, similar to "1, 3, 7, 8," function get_gongchengleibie ($ aid, & $ str, $ conn) {$ str = ""; $ query = mysql_query ("select * from gongchengleibie where pid = $ aid", $ conn ); while ($ row = mysql_fetch_array ($ query) {$ str. = $ row ["id"]. ","; get_gongchengleibie ($ row ["id"], $ str1, $ conn );}}

Gongchengleibie is a database table with a three-layer tree structure, as shown in figure

I want to remove the reference parameter $ str and use the return value method. I failed to try it myself.
How can I change it?
If it cannot be changed, why?

Thank you for your attention or answers.
If the information is incomplete or the problem description is unclear, I will immediately add a message to the sorry + request.

Reply content:

The code is as follows:

// Return the specified $ aid Project Category id and its subordinate category id. // parameter: // $ aid project category, int type // $ conn database connection // $ str, return value, string type // return: string, similar to "1, 3, 7, 8," function get_gongchengleibie ($ aid, & $ str, $ conn) {$ str = ""; $ query = mysql_query ("select * from gongchengleibie where pid = $ aid", $ conn ); while ($ row = mysql_fetch_array ($ query) {$ str. = $ row ["id"]. ","; get_gongchengleibie ($ row ["id"], $ str1, $ conn );}}

Gongchengleibie is a database table with a three-layer tree structure, as shown in figure

I want to remove the reference parameter $ str and use the return value method. I failed to try it myself.
How can I change it?
If it cannot be changed, why?

Thank you for your attention or answers.
If the information is incomplete or the problem description is unclear, I will immediately add a message to the sorry + request.

You just need to change it to this. if you have more, you won't talk about it.

function get_gongchengleibie($aid, $conn){    $str = "";    $query=mysql_query(" select * from gongchengleibie where pid=$aid",$conn);    while($row=mysql_fetch_array($query))    {        $str .= $row["id"].",";        $str .= get_gongchengleibie($row["id"], $conn);    }    return $str;} 

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.