Jump to content

sql update


pagegen

Recommended Posts

Are you replacing the 5 with 20 or trying to append 20 to the value?

 

Edit: the database field that is getting the information needs to be vchar in order to store the comma I believe. So you'd have to also make sure that's setup correctly.

Link to comment
Share on other sites

ok so here's what I'm thinking

 

// Connection to database stuff here

$dbc = mysqli_connect('host', 'user', 'password', 'dbname');

 

 

$newvalue = ','.20;

$fields = Array("yourfieldtoupdatehere")

 

// Foreach loop to only update the field where the value is 5

 

foreach ($fields as $fld) {

 

$query = "UPDATE table SET $fld = $fld+$newvalue' WHERE fld = 5";

mysqli_query($dbc, $query);

 

}

 

mysqli_close($dbc);

?>

 

See if that does the trick for ya, if anything it's how I"m trying to append 20 to the value that may fail.

Link to comment
Share on other sites

Assuming you are doing this to represent adding a fractional number, using the comma , as a decimal point separator character is a human convention that is only used in specific geographic locations. Computer programs uses a decimal point . as the decimal separator character.

 

If you want to use the comma , as a decimal point separator, you will need to convert the number into your local representation when you display it. It is not stored that way and you don't perform computer operations on it that way.

 

If you are doing this to store a list of comma separated values in one field, it is a bad idea.

Link to comment
Share on other sites

If you are only storing/retrieving them as is and you are not planning on searching for any of the values (i.e. you don't need to find the 44 in your example list), then storing them as a comma separated list is ok. Searching for the values is a different matter and if you plan on needing to search, you should store the individual values as one per row in a different table that is tied to your main table using a key/id value.

 

And what threw me off about if this was adding a decimal (.20) to the value was your use of the + in the first query posted.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.