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条)

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题