Results 1 to 7 of 7

Thread: When Insert .. but what when Update ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    When Insert .. but what when Update ?

    In this code:
    $Sql = "INSERT INTO Subject (ReplyNo) VALUES ('0')";
    $Result = mysql_query($Sql);
    Echo mysql_insert_id();

    I use ( Echo mysql_insert_id(); ) to echo the the current ID that Inserted

    but what can I use to know the current ID that updated ??

    I try that
    $Sql = "UPDATE Main SET tt='$tt' WHERE MainID=$MainID";
    $Result = mysql_query($Sql);
    Echo mysql_update_id();

    but give me error that (there is not any function like that (mysql_update_id()

  2. #2
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236
    I'm not sure there is a function for that. There is a function mysql_affected_rows() which returns how many records were updated/deleted. If you were doing an update with just one record, you could make sure it went through alright, you could use this to check it.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    V.G TheGoldenShogun

    Thank you too much TheGoldenShogun !! that is what I need..

  4. #4
    Also, if you don't want to add a duplicate row, you can use:
    Code:
    REPLACE table...

  5. #5
    Junior Member
    Join Date
    Jul 2002
    Location
    San Diego, CA, U.S.A
    Posts
    30
    I would honestly do it like this:

    PHP Code:
    $query "SELECT * FROM table";
    $result mysql_query($query$connect);

    while(
    $curr_id mysql_fetch_array($result))
    {
      
    $id_count $cur_id[id]; // This is the long way...
    }
    // $id_count is equal to the last id in the db! 

  6. #6
    How about:
    Code:
    SELECT id FROM table ORDER BY id ASC LIMIT 1

  7. #7
    Junior Member
    Join Date
    Jul 2002
    Location
    San Diego, CA, U.S.A
    Posts
    30
    that would work also, I like to take all my data out, because I usually it...

Posting Permissions

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



Click Here to Expand Forum to Full Width