The while variable goes out differently?

Source: Internet
Author: User
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 column ID to find out what the sub-column ID

The above method

should be the output

1, 2,

But only output
1,

But if you put
return $all _son = $row ["id"]. ",";
Switch
echo $all _son = $row ["id"]. ",";

Can normally show 1, 2,

Why is this?

How do I fix it?
I'm trying to get this method out to the end.

The

Let me in the where ID in MySQL

But now you can only output the first one, you can't use return, only echo?

Solving!


Reply to discussion (solution)

We recommend that you learn the basics first.


function Type_son_id_finder ($type _id) {
$query =mysql_query ("Select id from ' protduct_type ' WHERE ' f_id ' = ' $type _id '");
$all _son = ";
while ($row =mysql_fetch_assoc ($query)) {
$all _son. = $row ["id"]. ",";
}
return $all _son;
}

Return is placed in the loop and it jumps out of the current loop, so it ends with a loop, so you get only one result. 1
The correct result can refer to # # return after the loop

function Type_son_id_finder ($type _id) {
$query =mysql_query ("Select id from ' protduct_type ' WHERE ' f_id ' = ' $type _id '");
$all _son = ";
while ($row =mysql_fetch_assoc ($query)) {
$all _son. = $row ["id"]. ",";
}
return $all _son;
}

Thank you so much for knowing that I didn't turn back.

return $all _son = $row ["id"]. ",";

??? Every time? $all _son so just go back to the last??? The value,

Change to $all _son. = $row ["id"]. ",";
In the follow-up?? and 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.