Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Increment data to database (php - mysql)

Posted on 2009-06-28
4
Medium Priority
?
250 Views
Last Modified: 2012-05-07
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
Comment
Question by:Pedro Chagas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1600 total points
ID: 24732002
in 1 statement:
$sql = "UPDATE yourtable SET yourfield = CONCAT('" . mysql_real_escape_string($new_word) . "', ' ', yourfield ) WHERE id = 1234 ";

Open in new window

0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1600 total points
ID: 24732004
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
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 24732054
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
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1600 total points
ID: 24732091
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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
What we learned in Webroot's webinar on multi-vector protection.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question