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;