- Author was Featured
- Bought between 50 and 99 items
- Contributed a Tutorial to a Tuts+ Site
- Exclusive Author
- Has been a member for 5-6 years
- Interviewed on the Envato Notes blog
- Item was Featured
- Referred between 100 and 199 users
- Repeatedly Helped protect Envato Marketplaces against copyright violations
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?
try to use ‘<>’ instead ’!=’ 
Good luck
You can use:
"WHERE id NOT IN (" . $_GET['id'] . ")"
I think…. but haven’t tested it.
- Author was Featured
- Bought between 50 and 99 items
- Contributed a Tutorial to a Tuts+ Site
- Exclusive Author
- Has been a member for 5-6 years
- Interviewed on the Envato Notes blog
- Item was Featured
- Referred between 100 and 199 users
- Repeatedly Helped protect Envato Marketplaces against copyright violations
I tried both of these and they didnt work. Do I need to do the ID check after I do my date checks??
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)’
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.
$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());
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']
, Good Luck
$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());
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 
