1281 posts
  • 7 Years of Membership
  • Affiliate Level 4
  • Author Level 6
  • Blog Interview
+8 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?

461 posts Don't be a HATER!
  • Weekly Top Seller
  • Elite Author
  • Author Level 8
  • Featured Author
+6 more
CodeElite
says

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

Good luck

1173 posts
  • 6 Years of Membership
  • Australia
  • Author Level 5
  • Beta Tester
+4 more
Motionreactor
says

You can use:

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

I think…. but haven’t tested it.

1281 posts
  • 7 Years of Membership
  • Affiliate Level 4
  • Author Level 6
  • Blog Interview
+8 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
  • 6 Years of Membership
  • Australia
  • Author Level 5
  • Beta Tester
+4 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
  • 6 Years of Membership
  • Australia
  • Author Level 5
  • Beta Tester
+4 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.

461 posts Don't be a HATER!
  • Weekly Top Seller
  • Elite Author
  • Author Level 8
  • Featured Author
+6 more
CodeElite
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());


461 posts Don't be a HATER!
  • Weekly Top Seller
  • Elite Author
  • Author Level 8
  • Featured Author
+6 more
CodeElite
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
  • 6 Years of Membership
  • Affiliate Level 3
  • Collector Level 2
  • Exclusive Author
+3 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
  • 5 Years of Membership
  • Author Level 3
  • Collector Level 1
  • Exclusive Author
+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