Need help to update 2 rows in the same table, been searching & testing with no real luck.

I need to update 2 rows based on the URL below... id=145&contactuname=json101&contactid=7&memberid=1&confirm=2 Updating these fields: ustatus, memberid, contactid, contactuname Table structure:

CREATE TABLE `contacts` (
`id` INT(40) NOT NULL AUTO_INCREMENT,
`ustatus` TINYINT(1) NULL DEFAULT '0',
`memberid` INT(20) NOT NULL,
`contactid` INT(20) NOT NULL,
`contactuname` VARCHAR(31) NOT NULL,
`blocked` INT(1) NULL DEFAULT '0',
PRIMARY KEY (`id`)
)

No clue how these work, anyone able to show how my table could work with the queries below?

update table1
set col1 = a.col1, col2 = a.col2, col3 = a.col3 from 
(select col1, col2, col3 from table2 where <expression>) as a
where table1.col1 <expression>
UPDATE Table1
SET (Col1, Col2, Col3, Col4) = 
(SELECT Col1a, Col2a, Col3a, Col4a FROM Table2 WHERE Col5a=Table1.Col5) 
WHERE Col5 IN (SELECT Col5a FROM Table2 )

Recommended Answers

All 3 Replies

try this:

update table1, table2
set table1.col1 = table2.col1, table1.col2 = table2.col2, table1.col3 = table2.col3 where table1.col1 = table2.somefield

try this:

update table1, table2
set table1.col1 = table2.col1, table1.col2 = table2.col2, table1.col3 = table2.col3 where table1.col1 = table2.somefield

I'm not sure I understand?
I only have 1 table not 2

Why I never saw this... but solved with 2 updates:

$memberid = $_GET['memberid'];
$contactid = $_GET['contactid'];
$id = $_GET['id'];
mysql_query("UPDATE contacts SET blocked='0', status='0'  WHERE id='$id'") or die (mysql_error());
mysql_query("UPDATE contacts SET blocked='0', status='1'  WHERE memberid='$contactid' AND contactid='$memberid'") or die (mysql_error());
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.