Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

Increment data to database (php - mysql)

Hi experts, in my database I have a field that have this kind of format, word word word word, in practice can be "great bottle water fresh" or more words.
That field in database can be editable, every time I put a new word I put them in the beggining of string, in practice if I want put a new word (ex. super) the result would be "super great bottle water fresh".

For i do the upgrade I use this steps:
Call database and get the string "great bottle water fresh"
join variables $newone + $database_result and becomes "super great bottle water fresh".
upgrade database

My question is, this is the best way for do that? have other way to increment database without call the $database_result?

Regards, JC
0
Pedro Chagas
Asked:
Pedro Chagas
  • 3
3 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
in 1 statement:
$sql = "UPDATE yourtable SET yourfield = CONCAT('" . mysql_real_escape_string($new_word) . "', ' ', yourfield ) WHERE id = 1234 ";

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
note: this sounds however like bad design, aka each word should go to a dedicated row, instead of concatenating all the words into 1 string.
0
 
Pedro ChagasWebmasterAuthor Commented:
Hi @angelIII, thanks for your feedback.
I thing you give me a great solution, the problem is I don't understand in that way, and I need a practical example.
Usually I use this code for update the database:
mysql_query("update words set palavras='$newwordstring' where id='$other_variable'", $db);
===================================

How I put your solution in my line of code?

Regards, JC
 
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
yes:
$sql = "UPDATE words SET palavras= CONCAT('" . mysql_real_escape_string($newwordstring) . "', ' ', palavras) WHERE id = '$other_variable' ";
mysql_query($sql);

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now