dongyou7739 2015-12-11 10:17
浏览 70

php mysql两个表多个数据检查

If i have two query data with PHP MySQL like this

<?php
    $a=msyql_query("select * from users");
    while($b=mysql_fetch_array($a,MYSQL_BOTH))
    {
        $c=$b['username'];
    }

    $d=msyql_query("select * from new_users");
    while($e=mysql_fetch_array($d,MYSQL_BOTH))
    {
        $f=$e['username'];
    }
?>

here is my question i have two table in a database

1- users

2 - new_users

if new_users field data['username'] exists in users table['username'] then update those fields that data retrieved from new_users table.How can i overcome? I think there need to use array but give me some solution experts. just i will attached a picture what i want to do?

  • 写回答

3条回答 默认 最新

  • doutuan4361 2015-12-11 10:32
    关注

    Try this

    <?php
    $newuser=$mysqli->query("select * from newusers");
    $result=$mysqli->query("select * from users");
    
    while($res=$newuser->fetch_array())
    {
       while($user=$result->fetch_array())
      {
         if($res['name'] ==$user['name']){
           $mysqli->query("update user set information=.'$res['information'].'");
    
         }
    
     }
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog