Hey,
I am trying to do an insert statement whereby i add multiple queries based on value from a dropdown. Basically a user will be adding fitness courses to a website. This is done simply by going into the admin and filling in the following form:
http://www.glofamily.com/glo/images/courses.jpg
It looks quite simple, the gist of it is that each course is set on a specific date. I have all of this working perfectly. However the client has asked for something more as usual. Sometimes courses will rung on the same day but for multiple weeks, and instead of having to go in every week putting in a course for the same day they want a way to enable “Recurring courses” by a given number of weeks.
So in the image above you can see i have a “Recurring weeks” field. What i intend to do is when the user selects lets say ‘3’ it adds the course with the date of (as per the image) “03 06 2010” and also inserts another 2.
So there would in essence be 3 courses added, each with different dates. In this case it should add like so:
“03 06 2010”
“10 06 2010”
“17 06 2010”
You see what i mean? So there would be 3 separate inserts.
First of all, is this a good way to do this?
Secondly how can i do this in terms of the SQL?
I currently have this, but needs to somehow check to see the value selected from the dropdown add the date and then add any recurring weeks:
public function insertCourse($category){
$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'] ." ".$_POST['hours'].":".$_POST['minutes'].":00";
$startdate = "0000-00-00 ".$_POST['starthours'].":".$_POST['startminutes'].":00";
$enddate = "0000-00-00 ".$_POST['finishhours'].":".$_POST['finishminutes'].":00";
$sql = "INSERT INTO tbl_courses
(catID, locID, date, startdate, enddate, title, body, email, phone, image, date_added) VALUES
(
'".mysql_real_escape_string($_POST['catID'])."',
'".mysql_real_escape_string($_POST['locID'])."',
'".mysql_real_escape_string($date)."',
'".mysql_real_escape_string($startdate)."',
'".mysql_real_escape_string($enddate)."',
'".mysql_real_escape_string($_POST['title'])."',
'".mysql_real_escape_string($_POST['body'])."',
'".mysql_real_escape_string($_POST['email'])."',
'".mysql_real_escape_string($_POST['phone'])."',
'".mysql_real_escape_string($_FILES['image']['name'])."',
now()
)";
$result = mysql_query($sql) or die(mysql_error());
return "Successfully added event";
}
So somehow i need to check if the value is more than 1, and if it is then do the one insert and then another adding an extra 7 days to the first date and so on…?
Is this possible?
Apologies if i have confused you…
Thanks again…