简体   繁体   English

将变量从一个函数传递到同一控制器中的另一个函数

[英]Passing variable from one function to another function in same controller

I need to pass a id from a fuction to other function, i tried this way but i cant get the result.我需要将一个函数的 id 传递给其他函数,我试过这种方式,但我无法得到结果。 Can anyone spot the mistake and give me a solution.任何人都可以发现错误并给我一个解决方案。 This is the exact code i am using这是我正在使用的确切代码

public function splstaff($id)
{
    $staff = DB::select("SELECT staff_id FROM special_labs WHERE sno={$id}");
    $this->splstafflist($staff);
}

public function splstafflist($staff)
{
    $data=DB::connection('mysql3')->select("SELECT MD5(CONCAT(a.staff_id,a.dob,a.cat_id))  staffid,a.staff_id,a.dep_id,
     LOWER(CONCAT(a.legend,' ',a.staff_name))staff_name,a.photo,b.desi_name,IFNULL(c.degree,'')degree,b.desi_orderno,
     IFNULL(MIN(sp.date_promotion),a.doj) doj FROM staff_personal_copy a LEFT JOIN staff_designationmaster b ON a.desi_id=b.desi_id
     LEFT JOIN staff_qualification_view c ON c.staff_id=a.staff_id LEFT JOIN (camps.staff_promotion sp INNER JOIN staff_designationmaster sd
     ON sp.to_designation=sd.desi_id AND sp.status>0 INNER JOIN staff_desigmaster sd1 ON sp.from_design=sd1.desi_id AND
     sd1.desi_orderno!=sd.desi_orderno ) ON sp.staff_id=a.staff_id AND b.desi_orderno=sd.desi_orderno WHERE a.staff_id IN ('{$staff}')
     AND a.status=1 AND a.cat_id=1 GROUP BY a.staff_id,sd.desi_orderno ORDER BY b.desi_orderno,doj,a.staff_id");
    return view('research.labs.staff',['splfac'=>$data]);
}

Uptade the first function adding return intruction like this:更新第一个添加return指令的函数,如下所示:

public function splstaff($id)
{
    $staff = DB::select("SELECT staff_id FROM special_labs WHERE sno={$id}");
    return $this->splstafflist($staff);
}

I think you might write your fist line of code with less complicated way ...我认为你可以用不太复杂的方式编写你的第一行代码......

$value = DB::table('special_labs')->where('sno',$id)->pluck('staff_id')->first();
 return   $this->splstafflist($value);

the problem was in this line:问题出在这一行:

 $staff = DB::select("SELECT staff_id FROM special_labs WHERE sno={$id}");

you did not use get() method so the result will be a query builder, and when you got the result it will be an array even if it has only one result ... so I recommend using pluck to take only the column you want and first to get the value from the array result ..你没有使用 get() 方法,所以结果将是一个查询构建器,当你得到结果时,它会是一个数组,即使它只有一个结果......所以我建议使用 pluck 只获取你想要的列并首先从数组结果中获取值..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将变量从一个函数传递到同一控制器中的另一个函数(laravel 5) - Passing variable from one function to another function in same controller (laravel 5) Codeigniter:将post变量从一个函数传递到控制器中的另一个函数 - Codeigniter: passing a post variable from one function to another in a controller 将变量从一个函数传递到另一个函数 - Passing variable from one function to another function 将窗体数据数组从一个函数传递到同一控制器中的另一个函数 - Passing Form-data Array from one function to another function in same controller 将变量值从一个函数传递到另一个函数 - Passing variable value from one function to another 在控制器中将变量从一个功能转移到另一个功能 - Transfer variable from one to another function in controller 如何将变量从一个函数访问到同一项目中不同控制器中的另一个函数 - How to access a variable from one function into another function in a different controller in the same project 如何使用Codeigniter将变量从函数发送到同一控制器中的另一个函数 - how to send variable from function to another function in a same controller with codeigniter 变量从 function 传输到同一个 controller 中的另一个 function 的问题 - Problem of transmission of a variable from a function to another function in the same controller 将变量从一个ajax函数传递到另一个ajax函数 - passing variable from one ajax function to another ajax function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM