1

I have a dashboard of product.On dashboard it display all product details.There is check box to delete multiple product at a time. For that I am using this code:

    $id=array('0'=> 'ab','1'=> 'bc','2'=> 'cd','3'=> 'de',.......);
    $packids=implode("','", $id);
    $packids= ('ab','bc','cd','ef',.....);// n numbers of record
    $sql = "DELETE from app_and_page where `Package` IN ($packids) and `user_created`=$uid";
    $retval = mysql_query( $sql, $link );

This query is deleting only one row.How can I delete all the selected rows at a time.

Urvashi
  • 239
  • 2
  • 10

2 Answers2

1

I thing the issue in pack ids just try this In place of

$id=array('0'=> 'ab','1'=> 'bc','2'=> 'cd','3'=> 'de',.......);
$packids=implode("','", $id);
$packids= ('ab','bc','cd','ef',.....);// n numbers of record
$sql = "DELETE from app_and_page where `Package` IN ($packids) and `user_created`=$uid";
$retval = mysql_query( $sql, $link );

Use this

$id=array('0'=> 'ab','1'=> 'bc','2'=> 'cd','3'=> 'de',.......);
$packids=implode("','", $id);
$packids="('".$packids."')";
$sql = "DELETE from app_and_page where `Package` IN $packids and `user_created`=$uid";
$retval = mysql_query( $sql, $link );

It will work for you.

EDIT

Try like this

$sql = "DELETE from app_and_page where trim(`Package`) IN $packids and `user_created`=$uid";
Bibhudatta Sahoo
  • 4,808
  • 2
  • 27
  • 51
0

$packids= ('ab','bc','cd','ef',.....);// n numbers of record $sql = "DELETE from app_and_page where Package IN (substr($packids, 0, strlen($packids)-1)) and user_created=$uid"; $retval = mysql_query( $sql, $link );

Try this one. I think you have to remove last comma from our packids string.

Bibhudatta Sahoo
  • 4,808
  • 2
  • 27
  • 51
Shimul
  • 87
  • 1
  • 3
  • 12
  • Echo query comes like DELETE from app_and_page where Package IN ('ab','bc','cd','de') and user_created=2 but delete only one row – Urvashi Jun 19 '17 at 07:18