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:

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?

Recommended Answers

All 2 Replies


cellName = concat(cellName, '$The_New_Value')

It did work. Thank you very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.