Jump to content

Php/mysql - Select... Where... In Problem


murfitUK

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...