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 Quote Link to comment Share on other sites More sharing options...
ignace Posted April 3, 2010 Share Posted April 3, 2010 SELECT * FROM inventory WHERE username = '$username' Quote Link to comment 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 Quote Link to comment 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); Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.