While variables are different from each other? -Php Tutorial

Source: Internet
Author: User
While variables are different from each other?
function type_son_id_finder($type_id){        $query=mysql_query("SELECT id FROM `protduct_type` WHERE `f_id` = '$type_id'");        while ($row=mysql_fetch_assoc($query)) {                return $all_son = $row["id"].",";        }}

This method is to enter a parent topic ID to find the subtopic ID.

The above method

Should be output

1, 2,

But only outputs
1,

However
Return $ all_son = $ row ["id"]. ",";
Changed:
Echo $ all_son = $ row ["id"]. ",";

It can be displayed as 1, 2,

Why?

How can I solve this problem?
I want to output this method

1, 2

Let me IN mysql WHERE id IN (1, 2)

But now only the first one can be output. return is not supported, but echo?

Solution!


Reply to discussion (solution)

I suggest you study the basic knowledge first.


Function type_son_id_finder ($ type_id ){
$ Query = mysql_query ("SELECT id FROM 'Maid _ type' WHERE 'F _ id' = '$ type_id '");
$ All_son = '';
While ($ row = mysql_fetch_assoc ($ query )){
$ All_son. = $ row ["id"]. ",";
}
Return $ all_son;
}

If the return statement is placed in the loop, the current loop is exceeded. Therefore, only one result 1 is returned.
For the correct results, refer to #2. Place the return value after the loop.

Function type_son_id_finder ($ type_id ){
$ Query = mysql_query ("SELECT id FROM 'Maid _ type' WHERE 'F _ id' = '$ type_id '");
$ All_son = '';
While ($ row = mysql_fetch_assoc ($ query )){
$ All_son. = $ row ["id"]. ",";
}
Return $ all_son;
}

Thank you very much for understanding that I didn't expect it to be transferred back.

Return $ all_son = $ row ["id"]. ",";

??? Every time? ? $ All_son, so only? Returns the last ??? Value,

Change to $ all_son. = $ row ["id"]. ",";
In the cycle ?? ? Return $ all_son;

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.