rupam_jaiswal Posted April 3, 2010 Share Posted April 3, 2010 Hi, I am using the following mysql query statement: mysql_query("UPDATE inventory SET username='$username' WHERE username='$target->username' ORDER BY RAND() LIMIT 15"); now I want to also display to the user which rows were affected by the above query and list all those rows in an echo or something. I know i can use mysql_affected_rows() to find HOW MANY rows were affected but can you make a script that will list the rows that were affected? or is it not possible? Regards Link to comment https://forums.phpfreaks.com/topic/197456-get-actual-rows-affected-after-update/ Share on other sites More sharing options...
ignace Posted April 3, 2010 Share Posted April 3, 2010 SELECT * FROM inventory WHERE username = '$username' Link to comment https://forums.phpfreaks.com/topic/197456-get-actual-rows-affected-after-update/#findComment-1036420 Share on other sites More sharing options...
rupam_jaiswal Posted April 3, 2010 Author Share Posted April 3, 2010 SELECT * FROM inventory WHERE username = '$username' Hi, There can be a records with username = '$username' even before running the UPDATE query, so If use SELECT * FROM inventory WHERE username = '$username' then it will fetch all the records which have not been modified by UPDATE command. I want only the affected rows with the UPDATE command. Regards Link to comment https://forums.phpfreaks.com/topic/197456-get-actual-rows-affected-after-update/#findComment-1036472 Share on other sites More sharing options...
ignace Posted April 3, 2010 Share Posted April 3, 2010 $ids = array(); $query = "SELECT id FROM inventory WHERE username = '$target->username'"; $result = mysql_query($query); if ($result) { while (list($id) = mysql_fetch_row($result)) { $ids[] = $id; } } $query = "UPDATE inventory SET username = '$username' WHERE username = '$target->username'"; $result = mysql_query($query); echo 'Rows updated: ', implode(', ', $ids); Link to comment https://forums.phpfreaks.com/topic/197456-get-actual-rows-affected-after-update/#findComment-1036526 Share on other sites More sharing options...
fenway Posted April 4, 2010 Share Posted April 4, 2010 Then update a "modified" field, and check that afterwards. Link to comment https://forums.phpfreaks.com/topic/197456-get-actual-rows-affected-after-update/#findComment-1036787 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.