Adding additional data to a mysql field
Adding additional data to a mysql field
Hi All
I am sure this has been covered but not able to find anything. I have almost completed my project for work and I have one last section to do and that is to update a record.
What I want to do is add new data to the existing data field. I have created a text box but I am not sure how to add addition text to the field.
Any ideas or youtube videos would be great
Regards
Andy
I am sure this has been covered but not able to find anything. I have almost completed my project for work and I have one last section to do and that is to update a record.
What I want to do is add new data to the existing data field. I have created a text box but I am not sure how to add addition text to the field.
Any ideas or youtube videos would be great
Regards
Andy
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Adding additional data to a mysql field
You would want to use an UPDATE query to add or change info to an existing record
The indelible lord of tl;dr
Re: Adding additional data to a mysql field
Hi JackolanternJackolantern wrote:You would want to use an UPDATE query to add or change info to an existing record
I have read up on the coding for the update function but none of the articles tell me if it over writes over the current data with the new data. What I currently have is a text field full of data and I want to be able to add to this data when any work has been carried out.
Are you able to share any code that may help me with this.
Regards
Andy
Re: Adding additional data to a mysql field
Code: Select all
$query = "UPDATE `table` SET `field` = CONCAT(`field`, '{$new_data}') WHERE `conditions`='met'";
New Site Coming Soon! Stay tuned
Re: Adding additional data to a mysql field
Seems complex - I thought you'd just load the data into a$, then make a$=a$.$b; where $b is the new data you want to add on. Then write $a back to the database.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Adding additional data to a mysql field
If you look at the syntax of the UPDATE function, you will see that you specify which fields you want to alter. In this way, you can update all fields for a record, only a couple, most of them, or however you want to do it.
Torn's code is better since it does it in one database query.
However, you may want to look at the design of your database if you are concatenating values into a single field, because that may be violating the best practice of atomicity. Basically, that means one data piece should be stored in each field of a record and only one. The reason this is important is because, for example, if you have to go back later and write up reporting scripts for your database, those fields are going to be clusters of data you can't easily work with. It makes the design very brittle and inflexible.
Of course, there are good reasons for concatenating data in a field, such as some kind of programmatic logic (I can't think of any good examples off-hand). But it usually isn't a good idea to pile discreet pieces of data into a single field.
Torn's code is better since it does it in one database query.
However, you may want to look at the design of your database if you are concatenating values into a single field, because that may be violating the best practice of atomicity. Basically, that means one data piece should be stored in each field of a record and only one. The reason this is important is because, for example, if you have to go back later and write up reporting scripts for your database, those fields are going to be clusters of data you can't easily work with. It makes the design very brittle and inflexible.
Of course, there are good reasons for concatenating data in a field, such as some kind of programmatic logic (I can't think of any good examples off-hand). But it usually isn't a good idea to pile discreet pieces of data into a single field.
The indelible lord of tl;dr
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Adding additional data to a mysql field
Code: Select all
$newsp = $playerinfo3['spellpoints'] - 10;
$query = "UPDATE players SET spellpoints = '$newsp' WHERE playername = '$playername';
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Adding additional data to a mysql field
Yeah, that is how you would want to do it. If you are continuously adding on to the end of a field, you may want to review your data storage design
The indelible lord of tl;dr
Re: Adding additional data to a mysql field
Thanks guys
I will try this today.
The reason I want to add additional data to a filed that has data is because it is a call logging system. The engineer will go in to the ticket and add updates to that one ticket.
This is how the big boys look to do it but not sure if this is the correct way or not.
As you all know I have just started to use PHP and have come so far with all you guys helping me.
Regards
Andy
I will try this today.
The reason I want to add additional data to a filed that has data is because it is a call logging system. The engineer will go in to the ticket and add updates to that one ticket.
This is how the big boys look to do it but not sure if this is the correct way or not.
As you all know I have just started to use PHP and have come so far with all you guys helping me.
Regards
Andy
Re: Adding additional data to a mysql field
Akmost there Guys
Again thanks for your help.
I hope this will be the last thing I need to do. Please can you let me know how I get get the following in to just one submit button
Regards
Andy
Again thanks for your help.
I hope this will be the last thing I need to do. Please can you let me know how I get get the following in to just one submit button
Code: Select all
<form method = "POST" action="update.php">
<br><br>Update: <br><textarea name="Update" cols="100" rows="10"></textarea><br>
<input type="submit" value="submit"><br><br>
<?php
echo "<tr><td><center><A href='Update.php?id=$Ticket' >Submit</a></center></td><tr>" ;
?>
Andy