Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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