What is the difference between mysql_num_rows and mysql_affected_rows in PHP?
The main difference between mysql_num_rows and mysql_affected_rows in PHP is that mysql_num_rows returns the number of rows in a result set, while mysql_affected_rows returns the number of rows affected by the last INSERT, UPDATE, REPLACE, or DELETE query. To solve this issue, make sure to use mysql_num_rows when you want to get the number of rows in a result set, and use mysql_affected_rows when you want to get the number of rows affected by a query.
// Example of using mysql_num_rows
$result = mysql_query("SELECT * FROM users");
$num_rows = mysql_num_rows($result);
echo "Number of rows in result set: " . $num_rows;
// Example of using mysql_affected_rows
mysql_query("UPDATE users SET status = 'inactive' WHERE id = 5");
$num_affected_rows = mysql_affected_rows();
echo "Number of rows affected by the query: " . $num_affected_rows;