douge7771 2015-07-08 07:53
浏览 25

php中的函数变量

Hi how to write php code for this, I have file contain list of data for example

  AA123_jane_G-1
  AA456_oshi_K-3
  AA789_pritt_P-4

I read my file using

function myfile(){

     while (($data = fgetcsv($handle, 1000, "_")) !== FALSE) {
    ..................
    ........
     .......
   //get $student_id, $name, $class,
}

I need to get username and password using student_id from file

function getusernameandpassword($student_id){

 ........
 .......
  $result = mysql_query("SELECT student_id, username, password FROM account WHERE student_id= '".$student_id."'");
 ........
 //get $username and $password from other remote server
 ....... }

after execute the both function, I want to gather all the information of that student and insert to DB

   function insertDB(){
 ........
 .......
 mysql_query("INSERT INTO user_info 
(student_id, username, password, name, class) VALUES ($student_id,$username,$password,$name,$class)")
 ........
 .......
 //insert all the paramater get from both function for each student to localhost DB}

My question, how I write this function in 1 script using php. How to return value and how to get the value to be input for other function

  • 写回答

3条回答 默认 最新

  • douyudouchao6779 2015-07-08 08:22
    关注

    to use a function's variable outside of the function, you either return the variable and assign it to another variable, or set the desired variable as global inside the function, for example:

    function test(){
        global $variable;
    }
    

    and then you can use it any where inside the script.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀