busnut Posted February 17, 2009 Share Posted February 17, 2009 G'day, after doing quite some playing around with my update database conversion as listed in a previous thread or 2 where I wanted changes to fields to be recorded into another table, i've gone for the aspect of adding a history log into the same table, i've got this to work to a degree, but what happens is it records the information that is changed, but when a new change occurs, it writes over the existing change here is a bit of the code if ($depot1 <> $depot) $history0 = date(M) ." " . date(Y) .": Transferred from $depot1 to $depot"; if ($rego1 <> $rego) $history1 = date(M) ." " . date(Y) .": Transferred from $rego1 to $rego"; if ($active1=="N" && $active=="Y") $history0 = date(M) ." " . date(Y) .": Delivered to $depot"; if ($active1=="Y" && $active=="N") { $history0 = date(M) ." " . date(Y) .": Withdrawn from $depot"; $depot="Withdrawn"; } if (strlen($livery1)>2 && $livery=="") $history2 = date(M) ." " . date(Y) .": AOA removed"; if ($livery1<>$livery && $livery<>"") $history2 = date(M) ." " . date(Y) .": AOA for $livery"; $history = "\n". $history0 ."\n". $history1 ."\n". $history2; $update = "UPDATE table SET id = '$id', busno = '$busno', chassisbody = '$chassisbody', vin = '$vin', bodyno = '$bodyno', delivered = '$delivered', withdrawn = '$withdrawn', depot = '$depot', rego = '$rego', active = '$active', ac = '$ac', wc = '$wc', fuel = '$fuel', livery = '$livery', history = '$history' WHERE id='$id' "; The end result should be this over a period of time depending on what gets changed on that particular bus: Jan 2009: Bus delivered to Alpha Jan 2009: Rego changed from 123ABC to 456DEF Feb 2009: Transferred from Alpha to Bravo Mar 2009: Bus withdrawn from Bravo So what is happening is when there is a new change, it records over the existing notes in the 'history' field, where it should just start a new line and record new comments for that bus. And its only selected fields that gets a history note added. So where have I gone wrong or what haven't I added? And yes the code above is quite possibly messy, so would appreciate if somebody knows a cleaner way. Cheers Link to comment https://forums.phpfreaks.com/topic/145534-solved-insert-at-end-of-field/ Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 history = CONCAT(history,'\n','$history') See CONCAT() Link to comment https://forums.phpfreaks.com/topic/145534-solved-insert-at-end-of-field/#findComment-764063 Share on other sites More sharing options...
busnut Posted February 17, 2009 Author Share Posted February 17, 2009 history = CONCAT(history,'\n','$history') See CONCAT() thankyou, that worked brilliantly Link to comment https://forums.phpfreaks.com/topic/145534-solved-insert-at-end-of-field/#findComment-764106 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.