SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    inserting multiple rows

    Hello, I am trying to insert multiple rows in my table however it is only inserting one.

    This is the query:

    while( $i < $row = mysql_fetch_array($notification_query2))
    {
    mysql_query("INSERT INTO `notifIcations_data` (`post_id`, `user_id`, `status`) VALUES (LAST_INSERT_ID(), '".$row['user_id']."', '1')");
    }
    I'm trying to insert a new row for each $row['user_id'] but it only inserts it for the first id.

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    What's this for?

    $i < $row = mysql_fetch_array($notification_query2)

    I think you want only $row = mysql_fetch_array($notification_query2)

    Also, LAST_INSERT_ID() will continually change as you're doing new inserts. Is that the intended functionality?

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Are you aware of the INSERT ... SELECT syntax?

    Code sql:
    INSERT INTO tbl_temp2 (fld_id)
      SELECT tbl_temp1.fld_order_id
      FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;

    http://dev.mysql.com/doc/refman/5.5/...rt-select.html

    Might be relevant, might not ..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •