steviemac Posted February 2, 2012 Share Posted February 2, 2012 Hi I was hoping someone could help me out. I want to update one column in every row This is what I tried <?php include("db.php"); $query = sprintf("SELECT response FROM myuser WHERE status = '2'"); $data = mysql_query($query); ($result = mysql_fetch_array( $data )); $rs = $result ['response']; $rs = strtoupper($rs); $result = mysql_query("UPDATE myuser SET response ='$rs' WHERE status='2'") or die(mysql_error()); printf ("Updated records: %d\n", mysql_affected_rows()); ?> It will strtoupper all of the column 'response' but it takes the first row data and updates the rest of the rows with the same data. I know the problem is in my select statement but I'm not sure how to strtoupper each row with its own data. I appreciate any help. Thank you Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 2, 2012 Share Posted February 2, 2012 Backup the table, then run this query in phpMyAdmin. Alternately, you could leave the data as-is and just format it when you retrieve and display it. UPDATE myuser SET response = UPPER(response) WHERE status = 2 Quote Link to comment Share on other sites More sharing options...
steviemac Posted February 2, 2012 Author Share Posted February 2, 2012 Thank you very much. It worked perfectly. 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.