我需要将我的php函数的结果返回给我的代码

时间:2017-06-09 11:10:05

标签: php mysql

  $employee_id='E81OYKC';   // here is my employee id 

  getFileName($employee_id);  // here i am calling function

  echo $response; // here i want $response value.

  function getFileName($employee_id)
  {

      //Mysql Query to fetch data 

       $sql = mysql_query("SELECT work_experience, curr_designation from employee_registration where employee_id='$employee_id'") or die(mysql_error());

       //fetching data from server 

      while ($row = mysql_fetch_array($sql, MYSQL_ASSOC)) 
      {

        $curr_des = $row['curr_designation'];
        $work_exp = $row['work_experience'];
        $response =  $work_exp.' '.$curr_des;
        return $response;  // here is my result
      }
 }

//在这个代码中,我想在调用方法后得到$ response值,即getFileName(),但我得到空白值。

2 个答案:

答案 0 :(得分:0)

将您的回复收到变量,然后就可以使用了

 $response = getFileName($employee_id);  // here i am calling function

 echo $response;

答案 1 :(得分:-1)

你需要变量来获得例如

的响应
$response = getFileName($employee_id);

然后你print_recho $response

并确保不使用mysql_*。你可以使用mysqli_*

我做了一些改变..试试这个

$employee_id='E81OYKC';   // here is my employee id 

      $response = getFileName($employee_id);  // here i am calling function

      echo $response; // here i want $response value.

      function getFileName($employee_id)
      {

          //Mysql Query to fetch data 

           $sql = mysql_query("SELECT work_experience, curr_designation from employee_registration where employee_id='$employee_id'") or die(mysql_error());

           //fetching data from server 

          while ($row = mysql_fetch_array($sql, MYSQL_ASSOC)) 
          {

            $curr_des = $row['curr_designation'];
            $work_exp = $row['work_experience'];
            $response =  $work_exp.' '.$curr_des;
            return $response;  // here is my result
          }
     }