#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    22
    Rep Power
    0

    Multiple inserts by date


    I have a database to control classes in a school. I would like to be able to insert multiple classes at the same time.

    For example 1 class of the same type for every day of term that is to say 1 class for every day between 2 dates. Or 1 class for every (for example) Tuesday

    Currently to insert 1 class on one day I have the following code

    $query = "INSERT INTO classes (date,time, subject, teacher)
    VALUES ('$dt', $ti,'$sj', '$tc')";

    How could I do this?

    Thanks in advance
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,204
    Rep Power
    4279
    you would do it like this --
    Code:
    INSERT 
      INTO classes (date,time, subject, teacher)
    VALUES 
     ('2013-06-04', '09:37','math', 'miss jones')
    ,('2013-06-11', '09:37','math', 'miss jones')
    ,('2013-06-18', '09:37','math', 'miss jones')
    ,('2013-06-25', '09:37','math', 'miss jones')
    ,('2013-07-02', '09:37','math', 'miss jones')
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    22
    Rep Power
    0
    Thanks, yes that is ok but it means putting each date in manually.

    The courses normally last for 9 months so there are a lot of dates to input.

    Is there any way to insert 1 entry for every date (or every day of the week) between two given dates in one query?

    That is to say by specifying the start and end date you could insert 1 entry for every day of the course.
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,204
    Rep Power
    4279
    you would probably want to do all that type of logic with php, not sql
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    22
    Rep Power
    0
    Ok

IMN logo majestic logo threadwatch logo seochat tools logo