Page 1 of 1
Messaging
Posted: Mon Apr 12, 2004 10:03 pm
by nick2
Hello, I am trying to think up a way of messaging users..
I have a db named "tradeacc" and the fields Username, and password.. Now I was thinking maybe everytime you try and send a message it will create a new field.. as subject then sub- message..date etc
but how do I go about making a sub field?
please help!
Posted: Mon Apr 12, 2004 11:21 pm
by Steveo31
Like private messaging? Or an instant messenger?
Posted: Tue Apr 13, 2004 5:43 am
by malcolmboston
if its private messaging (like these forums its incredibly easy and was actually teh first major app i built
Mysql DB private_messaging
receiver
sender
message
date
status
Code: Select all
// pseudo code
$query = "SELECT * FROM private_messaging WHERE receiver = '$_SESSION[username]' ORDER BY DATE asc";
$result = mysql_query($query) or die(mysql_error())
$array = mysql_fetch_array($result, MYSQL_ASSOC);
this will get the messages that are for the user currently logged in, i used status to check if it had been read before or not
this should be a good starting point for you........
good luck
Posted: Tue Apr 13, 2004 10:26 am
by nick2
That wasnt what I was asking.. Everyone knows how to get info out.. and insert.. I would like to create fields.. and sub fields.. so can someone please answer this?
and yes its private messaging.
Posted: Tue Apr 13, 2004 10:30 am
by malcolmboston
whay would you ever need to create a new field for this?
Posted: Tue Apr 13, 2004 10:50 am
by kettle_drum
What do you mean sub-fields? You can store whatever the user sends in one field and then just parse it as long as you know the order of the items:
subject|subtitle|subsubtitle|message|psmessage|submessage|secretmessage
And if you do what another field, then just add one by updating the table.
Posted: Tue Apr 13, 2004 11:09 am
by nick2
thansk kettle.. can you give me an example on how to create a new field with code? thanks
Posted: Tue Apr 13, 2004 11:21 am
by kettle_drum
Code: Select all
ALTER TABLE `table_name` ADD `new_field` VARCHAR(255) DEFAULT 'test';
Thats the sql, you just need to call it with mysql_query() or the like - and change the values of course

Posted: Tue Apr 13, 2004 11:22 am
by nick2
thank you!
Posted: Tue Apr 13, 2004 11:27 am
by kettle_drum
No probs. But becareful if your allowing users to add new fields.
Posted: Tue Apr 13, 2004 11:50 am
by nick2
Ugh I am new to all of this so pelase easy!
lol I have user accounts.. and I want it to add the field on the line with the pecific username.
like
Nick | password | info1 | info2 | added message1
can you maybe tell me if this is rigth as well?
thanks!
Code: Select all
<?php
if ((!$_POSTїMsgU]) || (!$_POSTїsubject]) || (!$_POSTїMsg])) {
header ( "Location: Http://www.pixelfriendly.com/tradesys/sendmsg");
exit;
}
#variables#
$db_address = "localhost";
$db_name = "pixelfriendly_com";
$table_name = "tradeacc";
$db_user = "pixel";
$db_pass = "****";
#connection#
$connection = @mysql_connect($db_address, $db_user, $db_pass) or die(mysql_error());
#select db#
mysql_select_db($db_name) or die(mysql_error());
#create table#
$sql = "ALTER TABLE `tradeacc` ADD `$_POSTїsubject]` VARCHAR(255) DEFAULT '$_POSTїMsg]' & '|' & 'From:user' & 'Date send''";
#results#
$result = @mysql_query($sql, $connection) or die(mysql_error());
#sent#
echo " sent! ";
?>
Posted: Tue Apr 13, 2004 6:28 pm
by JAM
nick2 wrote:thansk kettle.. can you give me an example on how to create a new field with code? thanks
Just making sure before making comment...
Are you really interested in creating a new type of field in the database, rather than adding information to the existing database?
Code: Select all
$sql = "ALTER TABLE `tradeacc` ADD `$_POSTїsubject]` VARCHAR(255) DEFAULT '$_POSTїMsg]' & '|' & 'From:user' & 'Date send''";
... just doesn't look correct.