Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL
Author Message
Guardian2003
Site Admin



Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam

PostPosted: Sun Sep 17, 2006 4:42 am Reply with quote

I'm a bit stumped on this one.
I have a table that contains a field with multiple entries seperated by carriage returns and need to update the feild content by appending data to the list.
Assuming the table name is 'names' and the field is named 'salutation', the field type is 'longtext'.
The content of the field in phpmyadmin looks like this
Quote:

Mr
Mrs
Miss

I am using a php form to update the field but its the actual SQL syntax I cannot figure out, would I use INSERT (seems unlikely as I am not actually adding a 'record' or UPDATE?
 
View user's profile Send private message Send e-mail
kguske
Site Admin



Joined: Jun 04, 2004
Posts: 6437

PostPosted: Sun Sep 17, 2006 6:50 am Reply with quote

You could export the data to see what the insert looks like. The update SQL would be similar.

_________________
I search, therefore I exist...
Only registered users can see links on this board! Get registered or login!
 
View user's profile Send private message
Guardian2003







PostPosted: Sun Sep 17, 2006 7:27 am Reply with quote

Interesting idea, I had not thought of that!!
 
Guardian2003







PostPosted: Sun Sep 17, 2006 7:48 am Reply with quote

The field shows me its contents are actually
Code:
Mr\r\Mrs\r\Miss
Hmm,that has completely dumbfounded me lol
 
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Sun Sep 17, 2006 8:03 am Reply with quote

I will assume that you already have a string variable where you have concatenated the additional string data to it and all you are needing to do is the UPDATE. A simple update might look like this:

$sql = 'UPDATE names SET salutation = \'.$salutation.'\' WHERE <<whatever will get you that ONE row to be updates>>';

Edited: Sorry, I forgot the most important piece of information in how to restrict the update to just the one row!

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Guardian2003







PostPosted: Sun Sep 17, 2006 9:39 am Reply with quote

I figured out how to retrieve the data from the DB, I'm using
Code:
$result = mysql_query("SELECT * FROM `".$prefix."_names` WHERE `salutation` = '3'");

// saultation has a row id of 3 
   $row = mysql_fetch_array( $result );
   echo "Salutation: ".$row['salutation'];

Obviously I don't actually need the echo in there, it was just for testing purposes.
So all I need to do now is assign $something = $row['salutation'] and concatenate the additional data to the end and hope I do not have to do something weird with addslashes to get the \r into the DB as well.
I'll certainly test your code out Montego, thanks for posting it.
I wasn't sure which way to go (UPDATE v INSERT) as I'm only updating one field in the row and havent used UPDATE enough to be familiar with its use.
 
Guardian2003







PostPosted: Sun Sep 17, 2006 10:38 am Reply with quote

Just a quick update, yep, that UPDATE statement worked a treat, I tested it by getting the data then using the update to put it straight back in.
All I need to now is get a carriage return inbetween the two concatenated strings and I'm cooking with gas!
 
Guardian2003







PostPosted: Sun Sep 17, 2006 10:55 am Reply with quote

All done - thanks guys!
 
montego







PostPosted: Tue Sep 19, 2006 5:32 am Reply with quote

Well, that didn't take long to figure out! Laughing Good job!
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©