dougaimian1143 2013-08-19 08:45
浏览 29
已采纳

使用表A的内容更新表B?

I have 2 tables, Table A:

sid, phone, ts

And Table B:

id, phone, sid(NULL), ts

I have written a PHP script to connect, query and read in the data, but am not sure how to edit the data.

What I essentially want to do is match tableB phone with tableA phone and if match then update tableB column sid which is NULL with tableA sid.

I am sure this can be done with while and foreach loop but am not exactly sure how.

Can anyone please help?

  • 写回答

2条回答 默认 最新

  • douxishai8552 2013-08-19 09:12
    关注

    If you need to automatically update the db, then you should be using CRON job.

    Step 1 : Copy paste the following in a separate php file say, cron.php. Add the db connection part also. :

    $query_table1 = "SELECT * FROM table1";
    $result_table1= msyql_query($query_table1);
    while($row_table1 = mysql_fetch_array($result_table1)){
        $phone1 = $row_table1['phone'];
        $sid1 = $row_table1['sid'];
    
        $query_table2 =  "UPDATE table2 SET sid=$sid1 WHERE phone=$phone1";
        $result_table2= msyql_query($query_table2);
    }
    

    Step 2 : Go to your host control panel and go to cron. In that add a new cron job.

    If you need to execute the file every 1 min then, this would help the cause:

    * * * * * <command> #Runs every minute

    The basic syntax would be time /path/to/command arg1 arg2

    Link to Cpanel docs

    Cheers

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败