PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$outcome = "UPDATE orders SET status='$newstatus' WHERE orderno='$SR'";
$outcomeq = mysql_query($outcome, $db_conn) or die("Query $outcomeq Failed".mysql_error());
$return = mysql_affected_rows($outcomeq);
echo 'test '.$return.'';
I need to return a 1 or a 0 if the update query updates something, so i tried a row count, and echo'd that. For some reason it shows nothing even though 1 row has been updated. Any ideas?
Last edited by rsmarsha on Wed Apr 06, 2005 7:22 am, edited 1 time in total.
mysql_affected_rows returns a zero though if the update doesn't change anything. For instance if status was "paid" and you set status to "paid" via an update then even though the update has happened mysql_affected_rows would return 0.
hmm that seems to work for the update query, unless the status is not changed in which case it won't show a 1. I need it to show even if the status isn't changed.
Sorry I am confused about your requirement. If the sql is not sucessful you die (gracefully) (php stops). If not, judging from what you just said, the update is always 1 isn't it ?
mysql_affected_rows just lists the number of rows affected/that have been changed. Normally text goes something like "x Records updated in database". If no changes are made "No changes required in database".
It is for an external company to update finance app status on an order. They have some kind of auto recognition script that requires me to return a 1 or a 0. mysql_Affected_rows returns a 1 if updated but a 0 if no rows are changed. I need it to return a 1 if the query runs (finds a match to the query), if it updates or not. The important thing is that the match is found to the record, and if it needs changing it's changed, if not then i still get a 1 as long as it's found.
I would use a switch http://de.php.net/manual/en/control-str ... switch.php. I find it neater and easier to track/add more options. The default should be catching where none of the Status options are matched. You should always fail gracefully - (Option X is not a valid option. This message has been logged.)