PHP recursively queries the parent class, which can be output by echo and cannot be returned

Source: Internet
Author: User
For PHP recursive query, the parent class can be output by echo and cannot return & lt ;? Phpinclude_once (".. /conn. php "); function & nbsp; SontoFather ($ I) & nbsp; {& nbsp; $ SQL & nbsp ;=& nbsp;" SELECT & nbsp; 'parent _ I: Ask for PHP to recursively query the parent class, which can be output by echo and cannot be returned.
 include_once("../conn.php");
function SontoFather($i) 
{
 $sql = "SELECT `parent_id`,`cate_name` FROM `dlbz_gcategory` WHERE `cate_id`=".$i; 
echo $sql;
echo '
';
$result = mysql_query($sql);
$row=mysql_fetch_row($result);
//echo $row[1];
if($row[0]!=0)
{
$i = $row[0];
//echo $i;
//echo $row[1];
SontoFather($i);

}
else
{  
echo $row[1];
//$j=$row[1];
return $row[1];
}
}
echo SontoFather(3);
echo SontoFather(450);
?>

Echo SontoFather (3); this sentence can be output normally. that is, the parent class has no recursion problem. you can return the returned value or echo the output;

Echo SontoFather (450); the return output is not normal, but can be echo output.


Php? Return ?? Recursion? Echo
------ Solution --------------------
16 rows
SontoFather ($ I );
Change
Return SontoFather ($ I );
Related Article

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.