1277 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 100+ members
  • Has sold $40,000+ on Envato Market
  • Interviewed on an Envato blog
+7 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?

448 posts Don't be a HATER!
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+5 more
webinpixels says

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

Good luck

1173 posts
  • Has been part of the Envato Community for over 5 years
  • Located in Australia
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
Motionreactor says

You can use:

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

I think…. but haven’t tested it.

1277 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 100+ members
  • Has sold $40,000+ on Envato Market
  • Interviewed on an Envato blog
+7 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
  • Has been part of the Envato Community for over 5 years
  • Located in Australia
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
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
  • Has been part of the Envato Community for over 5 years
  • Located in Australia
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
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.

448 posts Don't be a HATER!
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+5 more
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());


448 posts Don't be a HATER!
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+5 more
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
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
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
  • Has been part of the Envato Community for over 4 years
  • Has sold $1,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
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