Messaging

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Messaging

Post 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!
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Like private messaging? Or an instant messenger?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post 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.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

whay would you ever need to create a new field for this?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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.
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

thansk kettle.. can you give me an example on how to create a new field with code? thanks
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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 :P
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

thank you!
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

No probs. But becareful if your allowing users to add new fields.
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post 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&#1111;MsgU]) || (!$_POST&#1111;subject]) || (!$_POST&#1111;Msg])) &#123;
header ( "Location: Http://www.pixelfriendly.com/tradesys/sendmsg");
exit;
&#125;

#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&#1111;subject]` VARCHAR(255) DEFAULT '$_POST&#1111;Msg]' & '|' & 'From:user' & 'Date send''"; 

#results#
$result = @mysql_query($sql, $connection) or die(mysql_error());

#sent#

echo " sent! ";
?>
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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&#1111;subject]` VARCHAR(255) DEFAULT '$_POST&#1111;Msg]' & '|' & 'From:user' & 'Date send''";
... just doesn't look correct.
Post Reply