-1

I have tried repeatedly and suffered a constraint. In this case I want to create an event trigger (insert) for the start date and end date. So from the start date inputted, the second date will be inputted, till the last date. In your opinion what is the most effective way to solve it?

start date: 2013-12-01 will be added 365 days,
The second date : 2013-12-02,
.
.
.
.,
Date of last : 2014-01-01
$sql = 'INSERT into cek_tgl (`tanggal`) VALUES ('.$date.')';
            for($i=1;$i<365;$i++)
            $sql .= ',('.$date.')';

            $connection = Yii::app() -> db;
            $command = $connection -> createCommand($sql);
            $command -> execute();

thanks for the help

deib97
  • 35
  • 9
  • 2
    huh? please clarify your question, show examples. I'm assuming you mean a date range from start to end and to fill in the middle values? – Jakub Dec 19 '13 at 08:06
  • Sorry, for my english is bad. Purpose of me is like to use afterSave () that contains a custom command to add a record to a table containing data first date, second date, third date, to the last date. – deib97 Dec 19 '13 at 08:15
  • Please rewrite your question so it explains clearly what you expect to happen, or it will be closed. – Mike Szyndel Dec 19 '13 at 08:56

1 Answers1

1

You need to write a stored procedure to do that. A trigger won't work as it's not allowed to insert value into the same table as the trigger is on.

Create a stored procedure that takes a start date as in parameter and then internally does 365 inserts.

Andreas Wederbrand
  • 38,065
  • 11
  • 68
  • 78