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?

Edited by BuildMyWeb
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.