Jump to content

update query & mysql_affected_rows()


aniesh82

Recommended Posts

Hi,

 

I have an UPDATE query and after executes it, I need to find out the ids of the records where the actual updation occurs.. I can find out the 'total updation' using the mysql_affected_rows() function.. But is there any php function or class available for this specific purpose?

 

thank you,

php developer,

Cochin-India.

Link to comment
Share on other sites

Just a thought as I am sure there is a better way, but when you're doing the update I would assume the update SQL specifies which row to update or it would not update the proper item... If so, you must b e passwing the id as part of the WHERE clause.

 

Could you loop through the items you are updating and add that id to an array after each query is executed?

 

For instance:

 

$ids = array(1, 3, 5, 7, 9);

foreach($ids as $v) {
    $SQL = "UPDATE table SET field = 'value' WHERE recordid = $v";
    $res = mysql_query($SQL, $conn);
    if($res) {
           $updated[] = $v
    }
}

 

Obviously the first array is just for examples sake :)

 

Just a thought

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.