keep first log_ID same as a parent_ID for every multiple insert query in mysql

codemania

I have PHP program which insert 4 row once when run. I want to keep first log_ID(auto incremental) same parent_ID for every 4 row.

like Below:

on 1st run program:

log_ID    name  parent_ID
======   =====  ==========
1         abc    1
2         def    1
3         ghi    1
4         jkl    1

on 2nd run program:

log_ID  name    parent_ID
======  =====   ==========
1        abc     1
2        def     1
3        ghi     1
4        jkl     1
5        xyz     5
6        abc     5
7        stu     5
8        jkl     5
Sherin Jose

This is a brief idea about how you can handle the problem..

<?php
$query1 =   "YOUR FIRST INSERT QUERY";
mysql_query($query1);
$last_log_id    =   mysql_insert_id();  //here you will get the log_id generated for the previous query (auto incremental)

//set the above last_log_id as parent_id of the previous row. ie., update query for row with `log_id` $last_log_id

$update_query   =   "YOUR UPDATE QUERY FOR FIRST ROW";

$query2 =   "YOUR SECOND INSERT QUERY WITH PARENT_ID AS $last_log_id";
mysql_query($query2);
$query3 =   "YOUR THIRD INSERT QUERY WITH PARENT_ID AS $last_log_id";
mysql_query($query3);
$query4 =   "YOUR FOURTH INSERT QUERY WITH PARENT_ID AS $last_log_id";
mysql_query($query4);
?>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get parent_id using mysql query?

From Dev

get first insert id for multiple insert using pdo in mysql

From Dev

Multiple insert in the same query?

From Dev

How Select Random with parent_id in mysql?

From Dev

How Select Random with parent_id in mysql?

From Dev

Mysql multiple insert query

From Dev

insert multiple ID in mysql row

From Dev

SQL Second INSERT query with ID of first one

From Dev

mysql insert into two tables id from first

From Dev

INSERT multiple ROWS for same ID Syntax Error

From Dev

MySQL multiple records of same id

From Dev

Same Auto Incremental ID Should be insert into Insert Query

From Dev

how to insert array values into mysql with the same id

From Dev

Insert same rows for a different id MySQL

From Dev

MySQL SUM cells with same ID and insert it in table

From Dev

Codeigniter MySQL : Insert record not be same with user id

From Dev

how to insert same id's to multiple tables in mysql. using php?

From Dev

mysql insert with select query to insert multiple rows

From Dev

Mysql insert into with multiple id from another table

From Dev

Create multiple words from one word by removing one character in every iteration by keeping first and last characters same for every word using mysql

From Dev

Select first unused id using mysql query

From Dev

Select first unused id using mysql query

From Dev

How to do a multiple insert using LAST_INSERT_ID() MySQL?

From Dev

How to do a multiple insert using LAST_INSERT_ID() MySQL?

From Dev

MySQL query to select records which don't have a particular status, data having same id with multiple statuses

From Dev

mysql query to if exists update else insert query without unique id

From Dev

Insert same ID connected to multiple selection options ID

From Dev

mysql- Averaging values every n row with same id

From Dev

mysql - insert results of query into same table with joins

Related Related

  1. 1

    How to get parent_id using mysql query?

  2. 2

    get first insert id for multiple insert using pdo in mysql

  3. 3

    Multiple insert in the same query?

  4. 4

    How Select Random with parent_id in mysql?

  5. 5

    How Select Random with parent_id in mysql?

  6. 6

    Mysql multiple insert query

  7. 7

    insert multiple ID in mysql row

  8. 8

    SQL Second INSERT query with ID of first one

  9. 9

    mysql insert into two tables id from first

  10. 10

    INSERT multiple ROWS for same ID Syntax Error

  11. 11

    MySQL multiple records of same id

  12. 12

    Same Auto Incremental ID Should be insert into Insert Query

  13. 13

    how to insert array values into mysql with the same id

  14. 14

    Insert same rows for a different id MySQL

  15. 15

    MySQL SUM cells with same ID and insert it in table

  16. 16

    Codeigniter MySQL : Insert record not be same with user id

  17. 17

    how to insert same id's to multiple tables in mysql. using php?

  18. 18

    mysql insert with select query to insert multiple rows

  19. 19

    Mysql insert into with multiple id from another table

  20. 20

    Create multiple words from one word by removing one character in every iteration by keeping first and last characters same for every word using mysql

  21. 21

    Select first unused id using mysql query

  22. 22

    Select first unused id using mysql query

  23. 23

    How to do a multiple insert using LAST_INSERT_ID() MySQL?

  24. 24

    How to do a multiple insert using LAST_INSERT_ID() MySQL?

  25. 25

    MySQL query to select records which don't have a particular status, data having same id with multiple statuses

  26. 26

    mysql query to if exists update else insert query without unique id

  27. 27

    Insert same ID connected to multiple selection options ID

  28. 28

    mysql- Averaging values every n row with same id

  29. 29

    mysql - insert results of query into same table with joins

HotTag

Archive