Php/Mysql - need help to insert and update multiple rows with a single query
Posted
by Guanche
on Stack Overflow
See other posts from Stack Overflow
or by Guanche
Published on 2010-04-03T14:38:54Z
Indexed on
2010/04/03
14:43 UTC
Read the original article
Hit count: 229
Hello, is there any way how in this situation insert and update DB with single queries?
$message = 'Hello to all group members';
$userdata = mysql_query("SELECT memberid, membernick FROM members WHERE groupid='$cid'") or die('Error');
while(list($memberid, $membernick) = mysql_fetch_row($userdata)) {
$result1 = mysql_query("INSERT INTO messages VALUES (NULL,'$membernick', '$memberid', '$message')") or die('Error');
$result2 = mysql_query("UPDATE users SET new_messages=new_messages+1, total_messages=total_messages+1 WHERE id='$memberid'") or die('Error');
}
© Stack Overflow or respective owner