The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
Array Delete - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23)
+--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26)
+--- Thread: Array Delete (/showthread.php?tid=595)



Array Delete - MHALL1 - 06-14-2017

I have a table that contains, id and pcnumber.

I can add new entries to the DB fine however want to replicate the array delete similar to removing users / permission groups etc by selecting check boxes. I thought this would be as easy as copying what in the admin_users.php and amending the deleteUsers function however can't seem to make it work.

I can see there is a deletebyId class however I'm not sure how to make this work / if this would be a better approach.

In the source code when the page is loaded, the correct ID is shown in each checkbox field, corresponding to the correct it / pcnumber; however this breaks when I try to put the [count] part in although i wasn't sure if this was needed given the correct IDs are already being returned.

Kind of minimal information but but hopefully outlines what I'm trying to achieve.

Any help appreciated,

Thanks




Array Delete - mudmin - 06-14-2017

The easiest thing is to do something like a foreach loop. So the checkboxes should represent the id of the row you're trying to delete.

Let's say they're all assigned to $deleteme

Code:
foreach ($deleteme as $d){
Code:
$db->query("DELETE FROM mytable WHERE id = ?",array($d));
Code:
}

That should do it.


Array Delete - MHALL1 - 06-17-2017

Perfect, thanks, that did the trick.


Array Delete - faguss - 06-18-2017

With this patch you can do this:

Code:
$db->delete("mytable",["id","IN",$array])



Array Delete - mudmin - 06-18-2017

I'm definitely going to look at rolling that out. I have 5 more weeks of camp coming up at my job and then it's back to coding.