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
https://forums.phpfreaks.com/topic/120279-update-query-mysql_affected_rows/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.