Jump to content

do an UPDATE to 2 tables conditional to field value in one table


BuildMyWeb

Recommended Posts

i have:

if( $stmt = $db_connect->prepare('UPDATE '.C_T_DRAGONS.' AS d, '.C_T_USERS.' AS u SET d.'.$prop.' = d.'.$prop.'+'.$val.', u.ap=u.ap-1 WHERE d.id = ? AND (SELECT u2.ap FROM '.C_T_USERS.' as u2 WHERE u2.id = ?) > 100') )

which echoes out as:

UPDATE dragons AS d, users AS u SET d.claws_dam = d.claws_dam+1, u.ap=u.ap-1 WHERE d.id = ? AND (SELECT u2.ap FROM users as u2 WHERE u2.id = ?) > 100

and am getting the following response:

Error : (1093) Table 'd' is specified twice, both as a target for 'UPDATE' and as a separate source for data

will this have to be done in 2 queries?  did a little searching and im thinking maybe the subquery is being refused?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.