Jump to content

[SOLVED] sql query only deleting one row at a time


dennismonsewicz

Recommended Posts

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 . '&section=' . $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?

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.

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.