954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Adding a value to a cell in MySQL

Hello everybody. I've been working on a PHP file that adds a value to a cell in one table in MySQL.
First I thought that the following code might work properly:

<?php
require("DB_Connector.php"); //The file that connects to the MySQL database required
mysql_query("update tableName set cellName= cellName + '$The_New_Value' where S_ID='$ID'",$connection);
?>

However, I learned later that this "+" mark is used only for math operations (Unlike JavaScript which uses the "+" mark instead of the "." used in PHP). I also tried the "." mark, but it didn't work! :@
Does anybody know how to add a value to a cell immediately without getting the content of that cell? I mean without writing the following code:

$getContent = mysql_query("select cellName from tableName",$connection);
while($contentArray = mysql_fetch_array($getContent))
{
     $newCellContent = $contentArray['cellName'] . $The_New_Value;
     $cell_ID = $contentArray['cell_ID'];
     mysql_query("update tableName set cellName='$newCellContent' where cell_ID='$cell_ID'",$connection);
}


So, I want to avoid writing the whole code I've already written, and I want to write a very shorter MySQL_Query code instead. Does anybody know how to do that?
Thanks.

Pro2000
Posting Whiz
351 posts since Jun 2007
Reputation Points: 44
Solved Threads: 23
 

This?

cellName = concat(cellName, '$The_New_Value')
Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

It did work. Thank you very much.

Pro2000
Posting Whiz
351 posts since Jun 2007
Reputation Points: 44
Solved Threads: 23
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: