Jump to content

Update all rows with one function


steviemac

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/256235-update-all-rows-with-one-function/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.