Jump to content

Recommended Posts

I have the table with the following structure

 

id bigin(11) auto_increment

group bigint(11)

date date

 

 

I'm trying to delete several dates within the same group. So i may be deleting one row or 100..who knows. I use a function that takes a dates array and then converts into into sql language. Its below

 

<?php
function array_to_sql($array)
	{
		$first = $array['0'];
		$sql = "AND date = '$first' ";

		$shift = array_shift($array);
	   
		if(!empty($array))
		{	
			foreach($array as $key => $date)
			{
				$sql .= "AND date = '$date' ";
			}
		}

		return $sql;

	}
?>

 

So if i have an array like the following

 

Array

(

    [0] => 2011-07-27

    [1] => 2011-07-28

    [2] => 2011-08-03

    [3] => 2011-08-05

)

 

 

 

using my function will spit out

 

DELETE FROM Rate_exceptions WHERE `group` = '4' AND date = '2011-07-27' AND date ='2011-07-28' AND date = '2011-08-03' AND date = '2011-08-05'

 

this query doesn't delete anything and i don't know why. If only use one date the deletion works for that one date but i want to be able to input several dates

 

anybody know what im doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/242912-help-with-syntax/
Share on other sites

I remember doing this a while back just can't remember how.

 

It would delete all rows that matched the group and any date defined in the query.

 

Yeah i'm using mysql_error and also double checking in the phpadmin sql box. It doesn't return any errors. Just no rows get deleted.

Link to comment
https://forums.phpfreaks.com/topic/242912-help-with-syntax/#findComment-1247699
Share on other sites

awesome thanks...i also figured out i could do it this way...but in() is cleaner. thanks!

 

DELETE FROM Rate_exceptions WHERE `group` = '4' AND date = '2011-07-27' OR (`group` = '4' AND date ='2011-07-28') OR (`group` = '4' AND date ='2011-07-29') OR (`group` = '4' AND date ='2011-07-30')
Link to comment
https://forums.phpfreaks.com/topic/242912-help-with-syntax/#findComment-1247703
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.