php - MySQL - nested where condition -


i trying delete multiple records data table. problem if need remove 3 records of deposit need not 'deposit' keyword 'balance' keyword.

table report: -------------------------------------------------------------------------------------- | report_id   action_id   action_name   balance   received   given  item_name   total| -------------------------------------------------------------------------------------- |    1           1        balance           0      10        0      gold         10  | |    2           2        deposit          10      10        0      gold         20  | |    3           3        deposit          20      10        0      gold         30  | |    4           4        balance           0       5        0      silver        5  | |    5           5        deposit           5       5        0      silver       10  | |    6           6        deposit          10       5        0      silver       15  | |    7           1        withdraw         30       0       10      gold         20  |      ..        ..... 

i have such piece of code:

... // empty array keys (action_id, action_name) $temparray  = array();    // generates string like: '(?,"deposit"),(?,"deposit")' $var = implode(',', array_fill(0,count($temparray), '(?,"deposit")'));   // generates query like: delete report (action_id, action_name) in ((?,"deposit"),(?,"deposit"))  $sql = "delete report (action_id, action_name) in (".$var.")";  try{  $db = getconnection(); $stmt = $db->prepare($sql); $result = $stmt->execute(array_values($temparray)); ... 

what trying do:

... // generate string like: '(?,"deposit" or "balance"),(?,"deposit" or "balance")' $var = implode(',', array_fill(0,count($temparray), '(?,"deposit" or "balance")'));   // generate query like: delete report (action_id, action_name) in ((?,"deposit" or "balance"),(?,"deposit" or "balance"))  $sql = "delete report (action_id, action_name) in (".$var.")"; 

i thought maybe work:

... // generate string like: '(?,"deposit","balance"),(?,"deposit","balance")' $var = implode(',', array_fill(0,count($temparray), '(?,"deposit","balance")'));   // generate query like: delete report (action_id, action_name,action_name) in ((?,"deposit","balance"),(?,"deposit","balance"))  $sql = "delete report (action_id, action_name,action_name) in (".$var.")"; 

any guidance welcome.

edit

updating answer because it's clear action_id not unique.

can modify query this:

$var = implode(',', array_fill(0, count($temparray), '?')); $sql = "delete report action_id in ($var) ".        "and action_name in ('deposit', 'balance')";  $db = getconnection(); $stmt = $db->prepare($sql); $result = $stmt->execute(array_values($temparray)); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -