dennismonsewicz Posted January 30, 2009 Share Posted January 30, 2009 I have some code that I am working with that only deletes one item at a time when it is supposed to delete multiple items... function removeItem() { $d = JRequest::getCmd('section'); $option = JRequest::getCmd('option'); $this->setRedirect('index.php?option=' . $option . '§ion=' . $d); $db =& JFactory::getDBO(); $cid = JRequest::getVar('cid', array(), 'request', 'array'); $count = count($cid); $id = implode(',',$cid); if ($count) { $db->setQuery('DELETE FROM #__' . $d . ' WHERE rowid = "' . $id . '"'); if (!$db->query()) { JError::raiseWarning( 500, $db->getError() ); } if ($count > 1) { $s = 's'; } else { $s = ''; } $this->setMessage('Message' . $s . ' removed ' . $id); } } When I print out the items deleted using $this->setMessage('Message' . $s . ' removed ' . $id); It shows all of the items that were "deleted" but the query only deletes the first item in the list... any ideas? Quote Link to comment Share on other sites More sharing options...
premiso Posted January 30, 2009 Share Posted January 30, 2009 You need to use MySQL IN syntax: $db->setQuery("DELETE FROM #__" . $d . " WHERE rowid IN(" . $id . ")"); Also your quotes were backwards. EDIT: Fixed the quotes. Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted January 30, 2009 Author Share Posted January 30, 2009 and what does the IN statement do exactly? Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted January 30, 2009 Author Share Posted January 30, 2009 that didn't work by the way Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted January 30, 2009 Author Share Posted January 30, 2009 fixed it, quotes were messed up in Query fixed code: $db->setQuery("DELETE FROM #__" . $d . " WHERE rowid IN(" . $id . ")"); I took out the single quotes in the IN syntax and it works Quote Link to comment Share on other sites More sharing options...
premiso Posted January 30, 2009 Share Posted January 30, 2009 Mysql IN Operator Yea, that was my mistake on the single quotes. I meant to remove them all together. Basically the IN operator acts as an OR statement, if the row_id is 1 OR the row_id is 2 execute this on those row_ids. Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted January 30, 2009 Author Share Posted January 30, 2009 thanks! I actually extended this topic to a new one... but i reckon that one can just "ride" out and be forgotten thanks again Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.