简体   繁体   English

如何从另一个表中获取值并将相同的数据插入到不同表中的特定行

[英]How to Fetch value from another table and INSERT the same data to specific row in a different table

I am seeking help on how to use data fetched from a different table and INSERT the same data to a DIFFERENT table while specifying the row which data will be stored considering the session created.我正在寻求有关如何使用从不同表获取的数据并将相同数据插入到不同表中的帮助,同时指定考虑创建的会话将存储哪些数据的行。

if (isset($_GET['apply'])) {

    $sess_id = $_SESSION['t_user_id'];
if (isset($_SESSION['UserName']) && $_SESSION['UserName'] == true) {

    $query = "SELECT * FROM users";
    $select_posts = mysqli_query($connection, $query);
    while ($row = mysqli_fetch_assoc($select_posts))
    {
    $ID = $row['ID'];
    }

    $query = "INSERT INTO users(commission)
    SELECT cost 
    FROM `tbl_jobs` 
    WHERE ID = '$sess_id' ";

    $update_user_role = mysqli_query($connection,$query);
    if (!$update_user_role) {

    die("QUERY FAILED" . mysqli_error($connection,$query));
    }
    header("Location: admin.php");
}
}


桌子

Currently its fetching the data from different table and posting to unintended row as per session.目前它从不同的表中获取数据并根据会话发布到意外的行。

I will like to see the data fetched from the different table being posted to row which is equal to username session created.我希望看到从不同表中获取的数据被发布到与创建的用户名会话相同的行。

I think you want update :我想你想要update

update users u join
       tbl_jobs j
       on u.id = j.user_id  -- guessing at the `JOIN` condition here
    set commission = j
    where u.id = ?;

Also note the use of ?还要注意使用? . . This is a parameter placeholder -- and an indication that you should be using parameters rather than munging query strings.这是一个参数占位符——并且表明您应该使用参数而不是修改查询字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在一行中获取具有相同 id 但在另一列中具有不同值的数据并在 php 中的表中显示一个月 - How to fetch data with same id in a row but different value in another column and display one month into table in php 如何从一个表中获取数据并插入到php中的另一个表中 - how to fetch data from one table and insert into another table in php 如何获取数据并插入到同一数据库中的另一个表中? - How to fetch data and insert into another table in same database? 从同一个表中获取不同的数据 - Fetch different data from the same table 从一个表中获取数组数据并插入到另一个表中 - Fetch array data from one table and insert into another table 从一个表中取出一列,在另一个表中搜索相同的列值,最后从第三个表中取出并显示数据 - Fetch a column from one table, search the same column value in another table and finally fetch and display data from the third table 我想从一个表中获取所有数据并将它们插入另一个表中,但只有第一行插入多次而不是所有行 - I want to fetch all data from a table and insert them in another table but only first row is inserting multiple time instead of all row 如何从另一个表进行内部联接并按特定的行值排序? - How to inner join from another table and order by specific row value? 如何将数据从一个表插入到另一个表 - How to insert data from a table to another table 连续打印同一张表中的不同数据 - print different data from same table in a row
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM