Home > Backend Development > PHP Tutorial > while 的变量传出去不一样?该如何解决

while 的变量传出去不一样?该如何解决

WBOY
Release: 2016-06-13 11:56:19
Original
1043 people have browsed it

while 的变量传出去不一样?

<br />function type_son_id_finder($type_id){<br />        $query=mysql_query("SELECT id FROM `protduct_type` WHERE `f_id` = '$type_id'");<br />        while ($row=mysql_fetch_assoc($query)) {<br />                return $all_son = $row["id"].",";<br />        }<br />}<br />
Copy after login

这个方法是输入一个父栏目ID 就查找到有什么子栏目ID

以上的方法

应该是输出

1,2,

但只能输出
1,

但如果把
                return $all_son = $row["id"].",";
改为:
                echo $all_son = $row["id"].",";

就能正常的显示出1,2,

这是为什么?

我如何解决?
我是想把这个方法最终输出成

1,2

让我在mysql中 WHERE id IN (1,2) 

但现在只能输出第一个,还不能用return, 只能用echo?

求解!
------解决方案--------------------

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;
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template