PHP在function()下得到变量

时间:2014-10-18 22:12:51

标签: php mysql sql oop mysqli

function subKategori($str){
    global $koneksi;
    $A = $str;

    $A1 = mysqli_query($koneksi, "select * from kategori where sub_id='".$A."'");
    $A2 = mysqli_num_rows($A1);
    if($A2 != 0){
        while($A3 = mysqli_fetch_array($A1)){
            $query1 = 'or id_kategori='.$A3['id'].' ';
            $query = ''.subKategori($A3['id']).' '.$query1.' '; //variable 1
        }
    }else{}
}


$idKategori = 1;
subKategori($idKategori);
$output = $query; //output variable 1

我想从外面获取变量...
因为,如果我使用subKategori();在mysqli_query()上,它显示了......

mysqli_query($connection, "Select * from item where id_category="'.$idKategori."' $output");

1 个答案:

答案 0 :(得分:1)

return是你的朋友。

function Test(){
  return "AAAAHHH";
}

Echo Test(); // Output "AAAAHHH"