[SOLVED]Inserting a row with one changed field
Moderator: General Moderators
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
[SOLVED]Inserting a row with one changed field
Hello. I want to make a mass Private Messaging system, but I'm not sure how to do it. My table is set up like this: message_id, sender, recipient, message, date. Mesasge_id is auto-incremented in the database, the sender stays constant (the admin that is sending this message), but the recipient has to change. I have a table of my users that contains the id's of every user (the user_id is what needs to go into the 'recipient'). I need a hint on the fastest way to do this, because we expect to have a lot of users. Any ideas?
Thanks!
Thanks!
Last edited by evilmonkey on Wed Jul 28, 2004 11:04 am, edited 1 time in total.
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
I had something like this in mind:
Is there a better way?
Code: Select all
<?php
//class declaration, other functions above...
function massmail ($message) {
$result = mysql_query("SELECT id FROM `users`");
while ($row=mysql_fetch_array($result)) {
$date = date("F d, Y");
mysql_query ("INSERT INTO `messages` (`sender`, `recipient`, `message`, `date`) VALUES ('$this->id', '".$row['id']."', '$message', '$date')", $db_link);
}
return true;
}
?>
Last edited by evilmonkey on Tue Jul 27, 2004 6:49 pm, edited 3 times in total.
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada