appending information

  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

morning all,

I'm writing a PHP/MySQL call logging system, for IT requests
I'm doing it so that I, as the administrator, can update with comments of my own. However, I'd like to be able to retain all previous comments I may have added, along with a timestamp for each comment.

My question is, can I do this inside of 1 field, effectively needing to append the data to previous entries?

Tommy :?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

1 field inside the db?

get your field data your usual way, then do:
$old_data .= $new_data;

and write your new $old_data field back to the DB. You might want some form of separator in there, so $old_data .= '|'.$newdata; or some such
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

1 field inside the database, yes
ideally, I would like end of 1 entry, then say a couple of CR's and then a timestamp, and other CR and then my new entry. look something like this

4/6/2004 - 13:00
user looked clueless

4/6/2004 - 13:05
user confirmed as management - cluelessness confirmed :D

is that any clearer? sorry if not
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

it's still pretty much the same thing, just do:
PHP Code: [ Select ]
 
$thetime = date("m/d/y H:i", time());
 
$old_data .= "\n\n$thetime\n$comment";
  1.  
  2. $thetime = date("m/d/y H:i", time());
  3.  
  4. $old_data .= "\n\n$thetime\n$comment";
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

thats great, its pretty much what I thought
I wasnt sure tho about whether or not I could use the \n inside the query string, but from what you're saying, its ok

Am I right in thinking that \n is treated as a new line if the query is inside double quotes?? otherwise inside ' - it is accepted as a literal character?
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

absolutely
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

excellent, some of this is starting to sink in at last!! :lol:

cheers for your help on this
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

I'm having trouble getting this to work, the MySQL database is displaying it in 1 line.

My code is like this

Code: [ Select ]
$newdata = "\n\n$sesstime\n$updateresponse";
                            
$requpdate = "UPDATE problems SET requestResponse='$newdata' WHERE callReference='$callReference'";

$updateresult = mysql_query( $requpdate );
  1. $newdata = "\n\n$sesstime\n$updateresponse";
  2.                             
  3. $requpdate = "UPDATE problems SET requestResponse='$newdata' WHERE callReference='$callReference'";
  4. $updateresult = mysql_query( $requpdate );


Although I'm including the \n - isnt this just for display purposes, MySQL cannot store the line breaks can it?
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

is the type for that field set to "Text" as is should be, or varchar like most default to?
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

it is actually set to BLOB, isnt that the same as TEXT?
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

BLOB is Binary
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

so if I change it to text, it should be ok??

when/what should I use binary for?
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

use binary for storing images, apps, anything not flat text
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

so a TEXT field will definitely recognise the line breaks?

sounds good, but how do I attach a file to it, and more to the point, retrieve it?
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

attach a file to which? you don't have to attach a file for what you want.

as to retrieving the data, you shouldn't need to change anything, just do a
SELECT whatever FROM wherever. That is, of course, unless the retrieval scripts does a binmode on the field to read it - in which case you'll probably want to change that.

this may seem a bit of a delayed question, but is there a specific reason you're not using separate rows for your entries? Doing so would allow you to say, pull up all comments made by such and such user, pull up all comments on such and such date, pull all comments that include the word "pattern" and so on.

*edit*
I guess all I'm saying in the above is that if all you want to do is write a little data every now and then, you could just drop your comments into a file on the HD and read that instead of using the database, as the latter is kind of like using an AH-64 to kill a mosquito
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

i dont need to read in files for this example, I was asking how I would go about it if I saw the need to with some other project

I see what you mean about writing to a file instead of a field, but I dont know how to do this, let alone retrieve it.
Can you give example code on how to do these actions?
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

This explains it better than I can
http://us4.php.net/manual/en/function.fopen.php
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

excellent, will give it a go
thanks for you help re: this topic

Post Information

  • Total Posts in this topic: 18 posts
  • Users browsing this forum: spork and 57 guests
  • 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 post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.