How To Find Affected Rows In MySQL
Computing : Learning PHP One point that confuses many with mySQL is when to use mysql_num_rows and mysql_affected_rows. Well, you should use the AFFECTED rows to find out exactly that - how many rows are affected by a query, thus this will be typically used with UPDATE queries. The num_rows function will be used with SELECT to tell you how many rows are selected. Let's say you update all rows WHERE the lastlogindate was a year in the past or greater. To find how many records that is, you use mysql_affected_rows. Also note that you don't need to pass the query id to it like you would with num_rows. Thus $whatever = mysql_query("UPDATE members SET inactive = '1' WHERE ...your parameters..."); To find how many rows this affected just use: $affected_number = mysql_affected_rows();
![]() Questions about PHP and mySQL:
|
|