Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysql双表多数据检查_Php_Mysql - Fatal编程技术网

Php mysql双表多数据检查

Php mysql双表多数据检查,php,mysql,Php,Mysql,如果我有两个像这样使用PHP MySQL的查询数据 <?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,MYSQ

如果我有两个像这样使用PHP MySQL的查询数据

<?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'];
    }
?>

这是我的问题,我在数据库中有两个表

1-用户

2-新用户

如果users表['username']中存在new_users字段数据['username'],则更新从new_users表检索到的数据所包含的字段。如何克服此问题? 我认为需要使用数组,但请给我一些解决方案专家。 只是我会附加一个我想做什么

试试这个

<?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'].'");

     }

 }
试试这个

UPDATE user as u 
INNER JOIN new_user as nu ON  u.username = nu.username
SET information='data'

您尝试了什么?代码编写服务也是如此。
<?php

    $newuser=$mysqli->query("select * from newusers");
    while($new_user=$newuser->fetch_array())
    {
        $name=$new_user['name'];
        $result=$mysqli->query("select * from users where username='$name'");
        if(!empty($result)){
                 while($user=$result->fetch_array())
                {   
                       $mysqli->query("update user set information=.'".$new_user['information']."'");
                  }
        }

    }

?>