murfitUK Posted January 3, 2009 Share Posted January 3, 2009 Created a page that lists various entries (doesn't matter what they are) from a database. Each one has unique ID field. Each line has a check box which user can tick and then click the delete button. This takes them to a "confirm deletion" page.The checkboxes are created <input type="checkbox" name="document[]" value="{$row['ID']}" /> in the usual way.When the confirm deletion page is loaded I do this: $entries = $_POST['document'] which takes all the ticked entries and puts them into the $entries array.Now, I want to build a query which selects the title of each entry to show the user before they delete them. The query is:"SELECT * FROM `documents` WHERE `id` IN ({$entries});"but it doesn't work and gives an error about unknown column "array" in where clause. I thought that I could feed $entries straight into the where clause but obviously not. Can anyone tell me what I need to do after $entries = $_POST['document'] to get it to work?Thanks. Link to comment Share on other sites More sharing options...
jeffman Posted January 4, 2009 Share Posted January 4, 2009 Maybe create a foreach loop and run your query for every member of $entries? Link to comment Share on other sites More sharing options...
murfitUK Posted January 4, 2009 Author Share Posted January 4, 2009 Was hoping I wouldn't have to do something like that, but in the end had no choice but to do foreach and build a string:$string = "";then foreach $entries add to the string so it looks something like $string="5,14,15,21," then knock off the last comma.Then I can use $string in the query ... IN ({$string}). Fortunately, because they are all numbers I don't need to worry about putting each number in quote marks. Link to comment Share on other sites More sharing options...
jeffman Posted January 4, 2009 Share Posted January 4, 2009 Oh, I get it now. FWIW, it might be simpler to write this:$e = implode (',', $entries); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.