Jump to content

mysql syntax query


blue-genie

Recommended Posts

I have the following situation.

I have a bunch of instances of a game in the database. The games can not overlap date wise.

with the insert I've managed to check if the date range is clear do the insert, however I now need to introduce an edit function, and I'm hitting a bit of a hurdle.

 

assume i have an entry call var1 whose startDate is 2010-07-01 and endDate is 2010-07-30

i have another entry var2 whose startDate is 2010-06-10 and endDate is 2010-06-15

 

i now get the var2 back to edit it and I want to change the endDate to 2010-06-30 which in theory is fine because no other entry is within that time range, however my current query

 

$result = mysql_query("select count(*)  as count FROM gameDetails WHERE startDate<=Date('".$newStartDate."') AND endDate>=DATE(' ".$newStartDate." ') OR startDate<=DATE(' ".$newEndDate." ') AND endDate>=DATE(' ".$newEndDate." ') " );

 

will return 1 because it counts itself right (var2)

 

so my question is this - I do a quick hack and check that if($row[count]>1) or is there a better way to write this script?

 

blu

 

Link to comment
https://forums.phpfreaks.com/topic/196453-mysql-syntax-query/
Share on other sites

i know the ID of the item i'm editing so i tried this

 

$result = mysql_query("select count(*)  as count FROM gameDetails WHERE gameID <> $editGameID AND startDate<=Date('".$newStartDate."') AND endDate>=DATE(' ".$newStartDate." ') OR startDate<=DATE(' ".$newEndDate." ') AND endDate>=DATE(' ".$newEndDate." ') " );

 

is this the best practice way of going about this?

Link to comment
https://forums.phpfreaks.com/topic/196453-mysql-syntax-query/#findComment-1031523
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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