1277 posts
  • Bought between 50 and 99 items
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 6-7 years
  • Interviewed on the Envato Notes blog
  • Referred between 100 and 199 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+2 more
rondog says

I use this to make sure no two date ranges conflict since their can only be one featured event:

$sql = mysql_query("SELECT * FROM de_featured_event WHERE '$startdate' BETWEEN start_date AND end_date OR '$enddate' BETWEEN start_date AND end_date") or die(mysql_error());

That works fine. What isn’t working for me is when I am editing an event, I run the same query except I say where id != $_GET[id]:

$sql = mysql_query("SELECT * FROM de_featured_event WHERE id != '".$_GET['id']."' AND '$startdate' BETWEEN start_date AND end_date OR '$enddate' BETWEEN start_date AND end_date") or die(mysql_error());

Basically I dont want it to select the date that I am editing. No matter what I do it always selects one row. That row being the one that is open hence the id != $_GET[id].

Any ideas?

436 posts Don't be a HATER!
  • Exclusive Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 4-5 years
webinpixels says

try to use ‘<>’ instead ’!=’ :)

Good luck

1173 posts
  • Australia
  • Beta Tester
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Sold between 10 000 and 50 000 dollars
Motionreactor says

You can use:

"WHERE id NOT IN (" . $_GET['id'] . ")"

I think…. but haven’t tested it.

1277 posts
  • Bought between 50 and 99 items
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 6-7 years
  • Interviewed on the Envato Notes blog
  • Referred between 100 and 199 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+2 more
rondog says

I tried both of these and they didnt work. Do I need to do the ID check after I do my date checks??

1173 posts
  • Australia
  • Beta Tester
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Sold between 10 000 and 50 000 dollars
Motionreactor says
I tried both of these and they didnt work. Do I need to do the ID check after I do my date checks??

Hmm, not sure. You may have to try a few configs.

Both of the above solutions work on a simple select statement to exclude a row, but from passing observation ‘<>’ is more efficient than ‘NOT IN ($val, $val)’

1173 posts
  • Australia
  • Beta Tester
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Sold between 10 000 and 50 000 dollars
Motionreactor says

I may be confused, but could you just use NOT BETWEEN '$start_date' AND '$end_date' to exclude rows with dates from a certain range?

Then you wouldn’t need an ‘id’ specifier.

436 posts Don't be a HATER!
  • Exclusive Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 4-5 years
webinpixels says
or maybe you should create a var for id,


$id = $_GET['id'];
//than call the query
$sql = mysql_query("SELECT * FROM de_featured_event WHERE id <> '$id' 
AND '$startdate' BETWEEN start_date AND end_date OR '$enddate' 
BETWEEN start_date AND end_date") or die(mysql_error());


436 posts Don't be a HATER!
  • Exclusive Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 4-5 years
webinpixels says
I may be confused, but could you just use NOT BETWEEN '$start_date' AND '$end_date' to exclude rows with dates from a certain range? Then you wouldn’t need an ‘id’ specifier.

+1,

[edit]

OR maybe use $_REQUEST['id'] :p, Good Luck

659 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 50 and 99 users
  • Sold between 10 000 and 50 000 dollars
  • United States
luckykind says
$sql = mysql_query("SELECT *
                    FROM de_featured_event 
                    WHERE id != '".$_GET['id']."' 
                    AND ('$startdate' BETWEEN start_date AND end_date 
                             OR '$enddate' BETWEEN start_date AND end_date"))
                    or die(mysql_error());
111 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 1 000 and 5 000 dollars
  • Taiwan
savorks says

in PHP use {$var} for insert variables in a string

i.e

$sql = “SELECT user_name FROM users WHERE user_name = ‘{$userName}’ LIMIT 0 , 1; ”;

Hope it works for ya :)

by
by
by
by
by
by